Omit controller name from URL mvc

后端 未结 2 889
悲&欢浪女
悲&欢浪女 2020-12-19 13:30

I\'m looking to do something similar to this post:

How to hide controller name in Url?

only without any sort of ID.

The server is running IIS 6 and t

相关标签:
2条回答
  • 2020-12-19 14:13

    Is your new routing rule positioned above the default routing rule of {controller, action, id} so that it has the opportunity to match first?

    0 讨论(0)
  • 2020-12-19 14:26

    The problem is your default route is still probably in place so it is matching it first and defaulting the rest of the inputs it expects. Based on your comment that the controller/action is working makes me think you didn't remove it or it is appearing first. Can you post your entire RegisterRoutes?

    Try making the route you defined the very first route and it should match almost anything you pass at it.

    EDIT: Added what your RegisterRoutes should look like:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        // This will match anything so if you have something very specific with hard coded
        // values or more items that will need to be match add them here above but do not
        // add defaulted values so it can still fall through to this.
        routes.MapRoute( 
            "RouteName", 
            "{action}", 
            new { controller = "Home", action = "Index" });
    }
    
    0 讨论(0)
提交回复
热议问题