ASP.NET MVC 5 のコントローラーでアクションの URL を作成する

コントローラーでも UrlHelper を使ってアクションの URL を作成できたのでメモしておく。

var helper = new UrlHelper(ControllerContext.RequestContext);

var indexPath = helper.Action("Index", "Home"); // => /

var indexUrl = helper.Action("Index", "Home", null, Request.Url.Schema); // => http://localhost:1065/