RouteCollection'不包含定义'MapMvcAttributeRoutes [英] RouteCollection' doesn't contain a definition for 'MapMvcAttributeRoutes

查看:1501
本文介绍了RouteCollection'不包含定义'MapMvcAttributeRoutes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不降级我的 ASP.Net 4.5.2 应用程序的 ASP.Net 4.0。当然,这给它带来了问题,比如未安装引用正确。我解决了其中的一些了,但我不能让我的头周围的错误:




CS106'RouteCollection不包含
定义的MapMvcAttributeRoutes',没有扩展方法
MapMvcAttributeRoutes接受式的第一个参数
RouteCollection'可以找到




 公共类RouteConfig 
{
公共静态无效的RegisterRoutes(RouteCollection路线){
routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);

routes.MapMvcAttributeRoutes();

routes.MapRoute(
产品名称:默认,
网址:{控制器} / {行动} / {ID},
默认:新{控制器=设备,行动=查看,ID = UrlParameter.Optional});
}
}



是否有人知道我要在这里做什么?



额外信息



这是我使用的命名空间:




  • 使用的System.Web

  • 使用System.Web.Mvc

  • 使用System.Web.Routing

  • 使用System.Web.Http



Visual Studio的社区2015


解决方案

支持路由属性(它提供了对 MapMvcAttributeRoutes 扩展方法的支持)MVC的唯一版本的 MVC 5



然而,的 MVC 5的只有的支持.NET框架4.5 和更高



所以,你有两个选择:




  1. 留在.NET框架4.5 +

  2. 降级到MVC 4,要么:


    1. 沟属性完全路由,并采用了约定的路由

    2. 与开源转到< A HREF =https://www.nuget.org/packages/AttributeRouting/相对=nofollow>属性的路由支持MVC 3和4

    < / LI>



作为微软的官方不再支持的任何版本.NET框架低于4.5.2 (除了3.5,但是这意味着降级到MVC 2的支持),我会强烈建议你认真考虑的第一选择。



I just had to downgrade my ASP.Net 4.5.2 application to ASP.Net 4.0. Of course this brings problems with it, like references that are not installed correct. I solved some of them already, but I can't get my head around an error:

CS106 'RouteCollection' does not contain a definition for 'MapMvcAttributeRoutes' and no extension method 'MapMvcAttributeRoutes' accepting a first argument of type 'RouteCollection' could be found

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

            routes.MapMvcAttributeRoutes();

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

Does someone know what I have to do here?

Extra info

Namespaces that I use:

  • using System.Web
  • using System.Web.Mvc
  • using System.Web.Routing
  • using System.Web.Http

Visual studio Community 2015

解决方案

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.

这篇关于RouteCollection'不包含定义'MapMvcAttributeRoutes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆