views:

39

answers:

1

Hi there. 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"); etc.

So what I don't like about this is amount of hardcoded 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 smth. else?

+1  A: 

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") %>
James Kolpack
Thank you so much. It's just what I wanted to get.
Alexander Efimov