asp.net mvc 5 - Remove controller 'Home' from URL in MVC 5 -
i need remove controller 'home' url of project, looks this: example.com/home/contact , want this: example.com/contact (also other sections services, our-team, gallery, etc.)
i tried remove '{controller}' appears before '{action}/{id}' in routeconfig.cs code, this:
namespace myproject { public class routeconfig { public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( "default", "{action}/{id}", new { controller = "home", action = "index", id = urlparameter.optional } ); } } } and controller 'home' disappears url, following links login , manage not work:
@html.actionlink("login here", "login", "account") @html.actionlink("manage website", "index", "manage") how make links work without displaying controller 'home' in url?
you'll need add following routeconfig.cs
routes.maproute( name: "contact", url: "contact", defaults: new { controller = "home", action = "contact" } ); make sure "default" route mapping last one.
Comments
Post a Comment