“The type or namespace name 'Route' could not be found” using “attribute routing”

后端 未结 4 2182
栀梦
栀梦 2021-02-19 08:57

Just trying to splice some code from one working project to another. The \"from\" project uses \"attribute routing\" where you embed [Route(…)] directives in the W

4条回答
  •  半阙折子戏
    2021-02-19 09:21

    Attribute Routing is native in ASP.NET MVC 5, or later, and ASP.NET Web API 2.

    However, there is a project that allows to use attribute routing it in previous version of ASP.NET MVC,and Web API. You should read this page carefully.

    As you can see in the linked page, this project is available as a NuGet package, so that it can be installed like this:

    • Install-Package AttributeRouting (for MVC)
    • Install-Package AttributeRouting.WebApi (for Web API)
    • Install-Package AttributeRouting.WebApi.Hosted (for self-hosted Web API)

    Please, be aware that the namespaces of attribute routing are different for each version and for MVC and Web API. So, you must browse the .dll included by the installed package to find out the right namespace, and change your using accordingly. For example:

    using AttributeRouting.Web.Http;
    

提交回复
热议问题