通过URL类可以生成URL连接。
[Route("")]
[Route("home")]
[Route("home/index")]
public IActionResult Index()
{
return Content(Url.Action("abc"));
}Code language: PHP (php)
注意 如果action不存在则会返回null的
[Route("")]
[Route("home")]
[Route("home/index")]
public IActionResult Index()
{
//return Content(Url.Action("Index"));
//return Content(Url.Action("Index", "Home"));
//return Content(Url.Action("Index", "Course", new { id=1,name="xiaopan" }));
return Content(Url.RouteUrl("blog"));
}Code language: PHP (php)
Previous: 08-自定义路由特性
Next: 10-路由在区域Area的使用