0

I'm new in ASP.NET MVC,

I have many actions in my controllers, so they return different ActionResults like this:

return View("blablabla"); 

or

return RedirectToAction("actionName", "controllerName");

So what I don't like about this is amount of hard-coded string values of actions' and controllers' names. If I change the name of controller or action I have to go through all my code to change code everywhere, where this action/controller was returned as an ActionResult.

So, guys, how do you manage this situation? Do you extract all the names into classes with constant or static readonly string fields with names of actions/controllers?

Or maybe you use something else?

1 Answer 1

1

Check out MvcContrib - it has a helper extension method which adds type-safe redirects. In Microsoft.Web.Mvc.LinkExtensions, there's an ActionLink<TController> method which can take an expression. You use it like:

<%=Html.ActionLink<HomeController>(c=>c.About(), "Go To About") %>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. It's just what I wanted to get.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.