内部のActionlinkの実装System.Web.Mvc.Html.LinkExtensions (System.Web.Mvc, Version=4.0.0.0)
は次のとおりです...
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
{
if (string.IsNullOrEmpty(linkText))
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText");
else
return MvcHtmlString.Create(HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, (string) null, actionName, controllerName, routeValues, htmlAttributes));
}
さまざまなパラメータの組み合わせによるユーティリティのオーバーロードがいくつかあります。
したがって、リンクを簡単に(テストされていない状態で)生成するための拡張メソッドを追加できるはずです...
public static MvcHtmlString InternalActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
{
if (string.IsNullOrEmpty(linkText))
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText");
else
RouteValueDictionary.Values.Add("id", htmlHelper.ViewContext.RequestContext.RouteData)
return MvcHtmlString.Create(HtmlHelper.GenerateLink(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection, linkText, (string) null, actionName, controllerName, routeValues, htmlAttributes));
}
public static MvcHtmlString InternalActionLink(this HtmlHelper htmlHelper, string linkText, string actionName)
{
return this.InternalActionLink(htmlHelper, linkText, actionName, (string) null, new RouteValueDictionary(), (IDictionary<string, object>) new RouteValueDictionary());
}
明らかに、必要な機能を正確に提供するには、いくつかの単純なラッパーオーバーロードを追加する必要があります。
次に使用するだけでhtml.InternalActionLink("Title", "Action")
、URLを生成するときに正しいIDがルートディクショナリに自動的に挿入されます。
ちなみに、次のActionLink()
オーバーロードはフレームワークによって提供されます-実装すればするほど、柔軟性が高まります...
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName)
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues)
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes)
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues)
public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName)