Why does Html.ActionLink render “?Length=4”

2019-01-01 04:52发布

I'm VERY confused as to why this code

Html.ActionLink("About", "About", "Home", new { hidefocus = "hidefocus" })

results in this link:

<a hidefocus="hidefocus" href="/Home/About?Length=4">About</a>

The hidefocus part is what I was aiming to achieve, but where does the ?Length=4 come from?

标签: asp.net-mvc
10条回答
零度萤火
2楼-- · 2019-01-01 05:20
Html.ActionLink("About", "About", "Home", new { hidefocus = "hidefocus" }, new { })

This will take the overload: string linkText, string actionName, string controllerName, Object routeValues, Object htmlAttributes

查看更多
萌妹纸的霸气范
3楼-- · 2019-01-01 05:20

Perhaps others had the same issue and need to supply a class value via HTMLAttributes parm. Here's my solution:

@Html.ActionLink("About", "About", new { controller = "Home", area = "" }, new { hidefocus = "hidefocus", @class = "nav-item nav-link" })

查看更多
孤独总比滥情好
4楼-- · 2019-01-01 05:25

With attribute names:

 @Html.ActionLink(linkText: "SomeText", actionName: "SomeAction", controllerName: "SomeControllerName", routeValues: new { parameterName = parameterValue}, htmlAttributes: null)
查看更多
泛滥B
5楼-- · 2019-01-01 05:32

The way I solved this is was adding a null to the fourth parameter before the anonymous declaration (new {}) so that it uses the following method overload: (linkText, actionName, controllerName, routeValues, htmlAttributes):

Html.ActionLink("About", "About", "Home", null, new { hidefocus = "hidefocus" })
查看更多
登录 后发表回答