开发者

whats is the best way of getting the name of the controller action that i am currently in

i have a number of asp.net-mvc controller actions that look like this:

 public ActionResult Home()
 {
 开发者_开发知识库     return View(new MyViewModel("Home"));
 } 

 public ActionResult Architecture()
 {
      return View(new MyViewModel("Architecture"));
 } 

is there anyway to get the name of the method that i am in to avoid having to hard code the string "Home" or "Architecture" ??


Sure:

var action = RouteData.Values["action"];


Have a look at T4MVC. http://mvccontrib.codeplex.com/wikipage?title=T4MVC

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜