1

Is it possible to override the controller name in ASP.NET MVC 4? It's needed for routing.

There is [ActionName("some-action-name")] attribute to override the action name.

Is it possible to do the same for a controller class name?

It's needed to make a controller name in the routing to have dashes, like "some-controller-name" instead of "SomeControllerName"

Zelid
  • 6,905
  • 11
  • 52
  • 76
  • I think that is not possible, because controller must be a unique to simple routing. – mrakodol Apr 05 '13 at 10:44
  • Try to add in Global.asax – Amit Apr 05 '13 at 10:45
  • 1
    Controller action names are also unique, but they have ActionNameAttribute that allows to override it. – Zelid Apr 05 '13 at 10:45
  • 5
    You wouldn't need to do that, you could just put a new one previous to the default one so it's get checked first. It would look like this (I have not tested it however): `routes.MapRoute( name: "MyName", url: "this-is-dashed/{action}/{id}", defaults: new { controller = "ThisIsNotDashed", action = "Index", id = UrlParameter.Optional } );` – Silvermind Apr 05 '13 at 10:48
  • Looks like you want to do this http://stackoverflow.com/a/2454016/351614 – Daniel Powell Apr 05 '13 at 11:17

1 Answers1

-3

Solved with routes. It's the only way to do it.

Thanks for comments.

Zelid
  • 6,905
  • 11
  • 52
  • 76