RouteCollection' doesn't contain a definition for 'MapMvcAttributeRoutes

删除回忆录丶 提交于 2019-12-01 20:14:16
NightOwl888

The only version of MVC that supports attribute routing (which provides support for the MapMvcAttributeRoutes extension method) is MVC 5.

However, MVC 5 only supports .NET framework 4.5 and higher.

So, you have 2 options:

  1. Stay on .NET Framework 4.5+
  2. Downgrade to MVC 4 and either:
    1. Ditch attribute routing altogether and use convention-based routing
    2. Go with the open source attribute routing that supported MVC 3 and 4

Being that Microsoft officially no longer supports any version of .NET Framework lower than 4.5.2 (except for 3.5, but that would mean downgrading to MVC 2 for support), I would highly recommend you consider the first option seriously.

I used routes.Ignore(). It seems to be working.

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

        routes.MapMvcAttributeRoutes();

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "device", action = "view", id = UrlParameter.Optional });
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!