RouteAttribute
在默认情况下,MMVC的特征路由功能是关闭的,我们需要调用代表当前路由表的RouteCollection对象的拓展方法 MapMvcAttributeRoutes开启此功能。 示例如下:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional}
);
}
如果不开启此功能,自定义路由后,会得到404错误提示。