1

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" ??

leora
  • 188,729
  • 360
  • 878
  • 1,366

2 Answers2

1

Sure:

var action = RouteData.Values["action"];
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
-1

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

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • what particular about T2MVC helps my problem ?? I see how this can replace hard coded strings with something more appealing but it still seems like its a hard coded Template where i want it to dynamically figure out what the name of the current controller action is ? – leora Nov 30 '10 at 01:18