Basically I want to make it so that: http://website.com/Home/About
Shows up as: http://website.com/About
The "home" controller showing up in the url would make the url longer for the user to read.
I tried to do the following:
routes.MapRoute(
name: "About",
url: "",
defaults: new { controller = "Home", action = "About", id = UrlParameter.Optional }
);
Could someone help me out please?
Try this. It also makes your URLs lowercase.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.LowercaseUrls = true;
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
And in your Home controller:
[Route("About")]
public ActionResult About()
{
return View();
}
Try something like this:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"OnlyAction",
"{action}",
new { controller = "Home", action = "Index" }
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", 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