我很困惑为什么这个代码
Html.ActionLink("About", "About", "Home", new { hidefocus = "hidefocus" })
此链接的结果:
<a hidefocus="hidefocus" href="/Home/About?Length=4">About</a>
隐焦部分是我的目标,但?Length=4从何而来?
我很困惑为什么这个代码
Html.ActionLink("About", "About", "Home", new { hidefocus = "hidefocus" })
此链接的结果:
<a hidefocus="hidefocus" href="/Home/About?Length=4">About</a>
隐焦部分是我的目标,但?Length=4从何而来?
当前回答
你忘记添加HTMLAttributes parm。
这将在没有任何更改的情况下工作:
Html.ActionLink("About", "About", "Home", new { hidefocus = "hidefocus" },null)
其他回答
只需删除“Home”(控制器的名称),这样代码将是:
Html.ActionLink("About", "About", new { hidefocus = "hidefocus" })
属性名:
@Html.ActionLink(linkText: "SomeText", actionName: "SomeAction", controllerName: "SomeControllerName", routeValues: new { parameterName = parameterValue}, htmlAttributes: null)
Html.ActionLink("About", "About", "Home", new { hidefocus = "hidefocus" }, new { })
这将承担过载: 字符串linkText,字符串actionName,字符串controllerName,对象路由值,对象htmlAttributes
请使用五(5)个参数的正确重载方法。例子:
@using (@Ajax.BeginForm("Register", "Account", null,
new AjaxOptions
{
HttpMethod = "POST",
OnSuccess = "OnSuccess",
OnFailure = "OnFailure",
OnBegin = "OnBegin",
OnComplete = "OnComplete"
}, new { @class = "form-login" }))
ActionLink的参数不正确,它试图使用“Home”值作为路由值,而不是匿名类型。
我相信你只需要添加new{}或null作为最后一个参数。
编辑:只是重新阅读了这篇文章,并意识到您可能希望将null指定为第二个最后一个参数,而不是最后一个参数。