为什么Html.ActionLink呈现“?Length = 4”

本文翻译自:Why does Html.ActionLink render “?Length=4”

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? hidefocus部分是我想要实现的目标,但是?Length=4来自何处?


#1楼

参考:https://stackoom.com/question/3SQp/为什么Html-ActionLink呈现-Length


#2楼

只需删除“ Home”(控制器的名称),使代码为:

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

#3楼

You forgot to add the HTMLAttributes parm. 您忘记添加HTMLAttributes参数。

This will work without any changes: 这将无需任何更改即可工作:

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

#4楼

As Jonathon Watney pointed out in a comment, this also goes for 正如乔纳森·沃特尼(Jonathon Watney)在评论中指出的那样,

Html.BeginForm() Html.BeginForm()

methods. 方法。 In my case, I was in a Create.cshtml targeting the post request of the corresponding controller + Create action and had 就我而言,我在一个Create.cshtml中,定位了相应控制器+ Create操作的发布请求,

using (Html.BeginForm("Create")) {
  @Html.AntiForgeryToken()
  ...
}

which was adding the querystring "?Length=6" to the form action when rendered. 呈现时将查询字符串“?Length = 6”添加到表单操作中。 Hinted by roryf's approved answer and realizing the string length of "Create" is 6, I finally solved this by removing the explicit action specification: 在roryf批准的答案的提示下,并意识到“ Create”的字符串长度为6,我终于通过删除显式操作规范解决了这个问题:

using (Html.BeginForm()) {
      @Html.AntiForgeryToken()
      ...
    }

#5楼

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

这将导致重载:字符串linkText,字符串actionName,字符串controllerName,对象routeValues,对象htmlAttributes


#6楼

具有属性名称:

 @Html.ActionLink(linkText: "SomeText", actionName: "SomeAction", controllerName: "SomeControllerName", routeValues: new { parameterName = parameterValue}, htmlAttributes: null)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值