开发者

How to handle actions and views names in my ASP.NET MVC application?

I have an ASP.NET MVC applications and i don't want to explicitly write the actions or the views names like this :

return RedirectToAction("Index"); or return View("Home");

what is the best practice for handling those strings?

I use Visual Studi开发者_如何学Co 2010 and ASP.NET MVC2


There's MVCContrib and inside there are extension methods allowing you to write:

return RedirectToAction<HomeController>(x => x.About());

Another possibility is T4 templates.


Use T4MVC. It will allow you to kill all magic strings in your code.


I've created a static class like so:

public static class Routing {
  public static RouteValueDictionary Index {
    get {
      return new RouteValueDictionary {
        { "controller", "Default" },
        { "action", "Index" }
      };
    }
  }
}

so i can use it like this:

return RedirectToAction(Routing.Index);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜