我很困惑为什么这个代码
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从何而来?
当前回答
只需删除“Home”(控制器的名称),这样代码将是:
Html.ActionLink("About", "About", new { hidefocus = "hidefocus" })
其他回答
搜索我的问题的答案落在这里,基本上是选择正确的重载@Html。ActionLink 这很重要。 我选择了一个不存在的重载(没有最后一个null), MVC没有这样的重载,导致一个错误的URL,类似于OP提到的东西。
个人提示:您可以使用匿名类型并不意味着您可以使用任何重载—这些重载是不存在的?-确定:它必须被定义! -在MVC 5.2时代来到这里
Html.ActionLink("About", "About", "Home", new { hidefocus = "hidefocus" }, new { })
这将承担过载: 字符串linkText,字符串actionName,字符串controllerName,对象路由值,对象htmlAttributes
只需删除“Home”(控制器的名称),这样代码将是:
Html.ActionLink("About", "About", new { hidefocus = "hidefocus" })
这工作得很好
@Html.ActionLink("Informationen", "About", "Home", new { area = "" }, new { @class = "nav-link" })
新增{area = ""}。
正如乔纳森·沃特尼在评论中指出的那样,这也适用于
Html BeginForm()。
方法。在我的情况下,我是在一个创造。cshtml针对对应控制器的post请求+ Create动作和had
using (Html.BeginForm("Create")) {
@Html.AntiForgeryToken()
...
}
哪个是添加查询字符串?当渲染时,Length=6"到表单动作。rroryf的认可答案暗示,并意识到“Create”的字符串长度是6,我最终通过删除显式操作规范来解决这个问题:
using (Html.BeginForm()) {
@Html.AntiForgeryToken()
...
}