开发者

Manage actions' and controllers' names in ASP.NET MVC

I'm new in ASP.NET MVC,

I have many actions in my controllers, so they return different ActionResults like this开发者_JS百科:

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?


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") %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜