【问题标题】:Attribute Routing in ASP.NET Core 1.0ASP.NET Core 1.0 中的属性路由
【发布时间】:2016-02-08 22:47:13
【问题描述】:
我是否需要配置任何东西才能在 ASP.NET Core 1.0 应用程序中使用属性路由?
以下内容似乎对我不起作用。当我转到 localhost:132/accounts/welcome 时,我期待使用此方法
public class AccountsController : Controller
{
[Route("welcome")]
public IActionResult DoSomething()
{
return View();
}
}
【问题讨论】:
标签:
asp.net-mvc-routing
asp.net-core
attributerouting
asp.net-core-1.0
【解决方案1】:
您可以使用的另一种方法是在您的班级上应用RoutePrefix 或Route。然后您就不必在操作属性上重复该部分。
[Route("[controller]")]
public class AccountsController : Controller
{
[Route("welcome")]
public IActionResult DoSomething()
{
return View();
}
}
【解决方案2】:
看来我需要在其中添加控制器令牌
public class AccountsController : Controller
{
[Route("[controller]/welcome")]
public IActionResult DoSomething()
{
return View();
}
}