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"

5
  • I think that is not possible, because controller must be a unique to simple routing. Commented Apr 5, 2013 at 10:44
  • Try to add in Global.asax Commented Apr 5, 2013 at 10:45
  • 1
    Controller action names are also unique, but they have ActionNameAttribute that allows to override it. Commented Apr 5, 2013 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 } ); Commented Apr 5, 2013 at 10:48
  • Looks like you want to do this stackoverflow.com/a/2454016/351614 Commented Apr 5, 2013 at 11:17

1 Answer 1

-3

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

Thanks for comments.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.