【发布时间】:2015-07-20 07:52:40
【问题描述】:
我写了一个自定义的HtmlHelper,如下:
public static MvcHtmlString MdActionLink(this HtmlHelper htmlHelper, string resourceId, string actionName, string controllerName, object routeValues = null, object htmlAttributes = null)
{
if (routeValues == null && htmlAttributes != null)
return htmlHelper.ActionLink(ResourcesHelper.GetMessageFromResource(resourceId), actionName, controllerName, htmlAttributes);
return htmlHelper.ActionLink(ResourcesHelper.GetMessageFromResource(resourceId),
actionName, controllerName,
routeValues,
htmlAttributes);
}
如果routeValues 和htmlAttributes 都为空也没关系。
但如果htmlAttributes 有值且routeValues 为空,则将a 标签呈现如下:
<a comparer="System.Collections.Generic.GenericEqualityComparer`1[System.String]" count="1" keys="System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.Object]" values="System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.Object]" href="/Home/Login?Length=7">Exit</a>
这有什么问题?
【问题讨论】:
-
我刚刚测试过,没有变化。
-
和往常一样,我猜,错误重载stackoverflow.com/questions/4357856/…
-
唯一接受
string作为前3个参数的ActionLink重载还需要第4个参数作为路由值,第5个参数作为html属性,这意味着如果你的if块评估为真,您将 htmlAttributes 作为路由值。只需删除这个助手 - 它完全没有内置的ActionLink()助手没有做的事情。
标签: c# model-view-controller html-helper actionlink