How to remove controller name from URL in MVC project

前端 未结 4 1554
不思量自难忘°
不思量自难忘° 2020-12-12 05:43

I have a URL like below and I need to remove the controller name (myController). I\'ve use several fixes but none fixed the issue. Please help me guys..

http://fold

4条回答
  •  甜味超标
    2020-12-12 06:04

    You could try inverting the routes definition by placing the more specialized route first. Also you probably didn't want to hardcode the action name as action but rather use the {action} placeholder:

    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            //routes.MapMvcAttributeRoutes();
    
        routes.MapRoute(
            name: "Special",
            url: "{action}",
            defaults: new { controller = "Home", action = "LandingIndex" }
        );
    
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
       }
    }
    

    Follow the below links :

    Link 1

    Link 2

    Link 3

提交回复
热议问题