Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a ActionNameAttribute in ASP.NET MVC 3 for class type declarations?

Can't imagine this question hasn't been asked yet... although, I can't find it.

So here it goes: I've used the ActionNameAttribute a lot on my action methods in ASP.NET MVC 3. Like this:

[ActionName("confirm")]
[HttpGet]
public ActionResult Confirm(string stuffTitle)
{
   ActionResult resultView = CreateSomeStuff(stuffTitle);
   return resultView;
}

But, how can I accomplish the same for classes? Like this:

[ActionName("personal")]
public class AccountController : Controller

With the ActionNameAttribute it's only possible on method declartions. But I guess it should somehow be possible on class type declarations. Maybe another attribute I haven't heard of yet? Some other workaround?

Anyone an idea? Thanks in advance!!

like image 781
Herman Cordes Avatar asked Jun 26 '11 20:06

Herman Cordes


1 Answers

I really have hard time understanding what are you after. You want to change the name of your controller or something? If so use a route:

routes.MapRoute(
    "FooRoute",
    "foo/{action}/{action}/{id}",
    new { controller = "Account", action = "Index", id = UrlParameter.Optional }
);

Now all requests to foo/someaction will be routed to the corresponding action of the Account controller.

like image 108
Darin Dimitrov Avatar answered Oct 05 '22 05:10

Darin Dimitrov