MVC路由约束

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
               name: "Details",
               url: "{controller}/{action}/{id}/{t}",
               defaults: new { action = "Details" },
               constraints: new { id = @"\d+", t = @"\d+" }    //路由约束   用于约束id和t为0到多个数字组成,当id或t为非数字时,会跳过这个路由,而尝试由下一个路由来匹配。
               );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

 

posted @ 2014-09-26 10:52  一夜秋2014  Views(310)  Comments(0Edit  收藏  举报