我很困惑为什么这个代码
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从何而来?
当前回答
搜索我的问题的答案落在这里,基本上是选择正确的重载@Html。ActionLink 这很重要。 我选择了一个不存在的重载(没有最后一个null), MVC没有这样的重载,导致一个错误的URL,类似于OP提到的东西。
个人提示:您可以使用匿名类型并不意味着您可以使用任何重载—这些重载是不存在的?-确定:它必须被定义! -在MVC 5.2时代来到这里
其他回答
Html.ActionLink("About", "About", "Home", new { hidefocus = "hidefocus" }, new { })
这将承担过载: 字符串linkText,字符串actionName,字符串controllerName,对象路由值,对象htmlAttributes
ActionLink的参数不正确,它试图使用“Home”值作为路由值,而不是匿名类型。
我相信你只需要添加new{}或null作为最后一个参数。
编辑:只是重新阅读了这篇文章,并意识到您可能希望将null指定为第二个最后一个参数,而不是最后一个参数。
请使用五(5)个参数的正确重载方法。例子:
@using (@Ajax.BeginForm("Register", "Account", null,
new AjaxOptions
{
HttpMethod = "POST",
OnSuccess = "OnSuccess",
OnFailure = "OnFailure",
OnBegin = "OnBegin",
OnComplete = "OnComplete"
}, new { @class = "form-login" }))
也许其他人也有同样的问题,需要通过HTMLAttributes parm提供一个类值。 以下是我的解决方案:
@Html。ActionLink("About", "About", new {controller = "Home", area = ""}, new {hidefocus = "hidefocus", @class = "nav-item nav-link"})
属性名:
@Html.ActionLink(linkText: "SomeText", actionName: "SomeAction", controllerName: "SomeControllerName", routeValues: new { parameterName = parameterValue}, htmlAttributes: null)