其他分享
首页 > 其他分享> > RouteAttribute

RouteAttribute

作者:互联网

 RouteAttribute的命名空间是System.Web.Mvc,区别与web api的RouteAttribute(它的命名空间是System.Web.Http)

  默认情况下mvc的特征路由(RouteAttribute)功能是关闭的,需要手动启动,启动方式:

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

            routes.MapMvcAttributeRoutes();//启用Attribute路由

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

标签:Web,RouteAttribute,System,action,routes,id
来源: https://www.cnblogs.com/Insist-Y/p/15655622.html