是否可以创建强类型操作 link 助手?
Is possible to create strongly typed action link helper?
我的目标很简单,我想在 ASP.NET MVC 中为具体控制器创建强类型的 ActionLink 助手。但它就是行不通;我以为我的路是对的...你能给我什么建议吗?
public static MvcHtmlString ActionLinkFor<TController>(this HtmlHelper<TModel> html, Expression<Func<TController, ActionResult>> action)
{
return MvcHtmlString.Empty;
}
用法非常简单 (<li>@(Html.ActionLinkFor<HelloController>(a => a.Index))</li>
),但我以错误消息结尾:
CS0428: Cannot convert method group 'Index' to non-delegate type 'System.Web.Mvc.ActionResult'. Did you intend to invoke the method?
而不是
<li>@(Html.ActionLinkFor<HelloController>(a => a.Index))</li>
使用
<li>@(Html.ActionLinkFor<HelloController>(a => a.Index()))</li>
我的目标很简单,我想在 ASP.NET MVC 中为具体控制器创建强类型的 ActionLink 助手。但它就是行不通;我以为我的路是对的...你能给我什么建议吗?
public static MvcHtmlString ActionLinkFor<TController>(this HtmlHelper<TModel> html, Expression<Func<TController, ActionResult>> action)
{
return MvcHtmlString.Empty;
}
用法非常简单 (<li>@(Html.ActionLinkFor<HelloController>(a => a.Index))</li>
),但我以错误消息结尾:
CS0428: Cannot convert method group 'Index' to non-delegate type 'System.Web.Mvc.ActionResult'. Did you intend to invoke the method?
而不是
<li>@(Html.ActionLinkFor<HelloController>(a => a.Index))</li>
使用
<li>@(Html.ActionLinkFor<HelloController>(a => a.Index()))</li>