1
我寫了一個自定義的HtmlHelper
如下所示:MVC ActionLink呈現錯誤的HTML?
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>
這有什麼錯呢?
我只是測試它,它不會改變。 –
像往常一樣,我猜,錯誤的重載http://stackoverflow.com/questions/4357856/razor-actionlink-autogenerating-length-7-in-url –
唯一重載的'ActionLink',接受一個'字符串'因爲前3個參數還需要第4個參數作爲路由值,第5個參數作爲html屬性,這意味着如果「if」塊的計算結果爲true,則將htmlAttributes作爲路由值進行重新渲染。只需刪除這個幫助程序 - 它根本不會執行內置的ActionLink()幫助程序。 –