Reputation: 1093
I have controller named PartialController and have a action method named AboutMe. I can access my action method from localhost/Partial/AboutMe . But i want to access it from localhost/About. So i changed my route like this:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Blog", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "About",
url: "About",
defaults: new
{
controller = "Partial",
action = "AboutMe",
id = UrlParameter.Optional
}
);
But i got 404 exception when trying to access AboutMe action from localhost/About. Need advice.
Upvotes: 0
Views: 43
Reputation: 1898
Define your About Route
first. Order matters when it comes to routing, they are applied in the order in which they are defined.
routes.MapRoute(
name: "About",
url: "About",
defaults: new
{
controller = "Partial",
action = "AboutMe",
id = UrlParameter.Optional
}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Blog", action = "Index", id = UrlParameter.Optional }
);
Upvotes: 1