Do I need to configure anything to use attribute routing in an ASP.NET Core 1.0 application?
The following doesn't seem to be working for me. I was expecting to hit this method when I go to localhost:132/accounts/welcome
public class AccountsController : Controller
{
[Route("welcome")]
public IActionResult DoSomething()
{
return View();
}
}
An alternative you can use is to apply a RoutePrefix
or Route
on your class. Then you won't have to repeat that part on the action attributes.
[Route("[controller]")]
public class AccountsController : Controller
{
[Route("welcome")]
public IActionResult DoSomething()
{
return View();
}
}
Looks like I needed to add the controller token in there
public class AccountsController : Controller
{
[Route("[controller]/welcome")]
public IActionResult DoSomething()
{
return View();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With