我在 ASP.NET 5 中启动了一个新的 Web API 2.0 项目。我尝试创建自定义 RoutePrefixAttribute 类,但出现此错误
The type or namespace name 'RoutePrefixAttribute' could not be found
(are you missing a using directive or an assembly reference?) {ProjectName}.DNX Core 5.0
我应该改用其他类吗?
最佳答案
在 MVC 6 中确实没有 RoutePrefixAttribute
。在 Controller 上应用 [Route]
属性现在将充当路由前缀:
[Route("api/[controller]/[action]")]
public class ProductsController : Controller
{
[Route("{id:int}")]
public JsonResult Details(int id)
{
// ...
}
}
这将匹配 api/Products/Details/42
。
另见 this blogpost作者:Filip W。
关于c# - ASP.NET 5 中的 RoutePrefixAttribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31766427/