Url Routing for Asp.net mvc
I am using ASP.Net MVC2 C# and I have a URL like below:
http://localhost:2107/News/NewsHome/NewsDetails/Celebrate_the_dedication_of_healthcare_quality_professionals_during_National_Healthcare_Quality_Week
Here News is Area and NewsHome is the controll开发者_运维百科er but I want the URL to look like this
http://localhost:2107/NewsDetails/Celebrate_the_dedication_of_healthcare_quality_professionals_during_National_Healthcare_Quality_Week
Is there any option to get area and controller name from the URL?
You can define a route like "NewsDetails/{name}
and specify the area, controller and action in the defaults
parameter (eg, new { area = "News", controller = "NewsHome", action = "NewsDetails" }
).
If you define the route as "{action}/{name}"
, it will swallow up all of your other routes too.
Define a new Route
routes.MapRoute(
"News", // Route name
"{controller}.aspx/{action}/{id}", // URL with parameters
new { area="News", controller = "NewsHome", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
精彩评论