ASP.NET Core 1.0中的属性路由

Sam*_*Sam 4 asp.net-mvc-routing attributerouting asp.net-core asp.net-core-1.0

我是否需要在ASP.NET Core 1.0应用程序中配置任何使用属性路由的东西?

以下似乎对我不起作用.当我去localhost:132/accounts/welcome时,我期待这个方法

public class AccountsController : Controller
{

   [Route("welcome")]
   public IActionResult DoSomething()
   {
       return View();
   }

}
Run Code Online (Sandbox Code Playgroud)

Tse*_*eng 7

你可以使用另一种方法是应用RoutePrefixRoute在您的类.然后,您不必在动作属性上重复该部分.

[Route("[controller]")]
public class AccountsController : Controller
{
   [Route("welcome")]
   public IActionResult DoSomething()
   {
       return View();
   }
}
Run Code Online (Sandbox Code Playgroud)