我写了一个自定义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
为null,则会将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>
它出了什么问题?
答案 0 :(得分:1)
试试这个:
public static MvcHtmlString MdActionLink(this HtmlHelper htmlHelper, string resourceId, string actionName, string controllerName, object routeValues = null, object htmlAttributes = null)
{
if (routeValues == null)
routeValues = new RouteValueDictionary();
if (htmlAttributes == null)
htmlAttributes = new Dictionary<string, object>();
htmlHelper.ActionLink(ResourcesHelper.GetMessageFromResource(resourceId),
actionName, controllerName,
routeValues,
htmlAttributes);
}