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
精彩评论