📅  最后修改于: 2022-03-11 14:49:19.134000             🧑  作者: Mango
By using the new [controller] token in your attribute routes you can ensure
that the controller name in the route, is kept in sync with the name of the
controller class. In the example below, [controller] will always be expanded
to the name of the controller regardless of any future refactorings – in this
case it will be Hello.
[Route("[controller]")] // there are placeholders for common patterns
as [area], [controller], [action], etc.
[HttpGet("")] // empty is valid. url.com/prefix
[Route("")] // empty is valid. url.com/
[HttpGet("/otherprefix/name")] // starting with / won't use the route prefix
[HttpGet("name/{id}")]
public IActionResult Index(int id){ ... // id will bind from route param.
[HttpGet("{id:int:required}")] // you can add some simple matching rules too.