I have a controller called InstallationController
, and a fancy report representation of an installation called a Rate Card, but the end user insists on calling installations themselves Rate Cards. I would like him to see the URL http://site/RateCard/Edit/3, where this gets routed actually as http://site/Installation/Edit/3. How can I do this in MVC 3 RC2?
An alias name for an action method is provided by using ActionName attribute. Also it is necessary to change the route template in the WebApiConfig. cs.
CSharp Online Training ActionName attribute is an action selector which is used for a different name of the action method. We use ActionName attribute when we want that action method to be called with a different name instead of the actual name of the method.
ASP.NET MVC Routing does the same thing; it shows the way to a request. Basically, routing is used for handling HTTP requests and searching matching action methods, and then executing the same. It constructs outgoing URLs that correspond to controller actions. Routing the map request with Controller's Action Method.
A controller is just a class (for example, a Visual Basic or C# class). The sample ASP.NET MVC application includes a controller named HomeController. cs located in the Controllers folder.
A couple of options are, you can either rename the controller to RateCardController
, or add a new route that directs to the Installation controller, like:
routes.MapRoute(
"RateCard", // Route name
"RateCard/{action}/{id}", // URL with parameters
new { controller = "Installation", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With