设置路由如下:
MapRoute(
                "NewsList",
                "News/List/{NewTypeId}/{*values}",
                new { controller = "News", action = "List" }
            );
如果我传入三个参数,
我希望出来的URL是这样:News/List/China/2008/01但实际出来的结果却是:News/List/China/?year=2008&year=01不知道是不是设置错误,请高手帮忙

解决方案 »

  1.   

    这个原因是因为你Route放置顺序不对引起的。下面这样放正常,会生成你想要的格式http://10.0.0.69:70/news.ashx/newlist/2008/1            routes.MapRoute(
                    "news",
                    "news.ashx/newlist/{year}/{day}",
                    new { controller = "news", action = "newlist", year = "year", day = "year" }
                    );            routes.MapRoute(
                    "Default",                                              // Route name
                    "{controller}.ashx/{action}/{id}",                           // URL with parameters
                    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
                );
    如果是这样放,格式就成了http://10.0.0.69:70/news.ashx/newlist?year=2008&day=1            routes.MapRoute(
                    "Default",                                              // Route name
                    "{controller}.ashx/{action}/{id}",                           // URL with parameters
                    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
                );
                routes.MapRoute(
                    "news",
                    "news.ashx/newlist/{year}/{day}",
                    new { controller = "news", action = "newlist", year = "year", day = "year" }
                    );
      

  2.   

    Route 是按顺序进行匹配的,能匹配第一条,下面就不在匹配,所以进行URL重写要注意匹配顺序。