我很困惑为什么这个代码

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时代来到这里

其他回答

你忘记添加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)

请使用五(5)个参数的正确重载方法。例子:

@using (@Ajax.BeginForm("Register", "Account", null,
    new AjaxOptions
    {
        HttpMethod = "POST",
        OnSuccess = "OnSuccess",
        OnFailure = "OnFailure",
        OnBegin = "OnBegin",
        OnComplete = "OnComplete"
    }, new { @class = "form-login" }))

搜索我的问题的答案落在这里,基本上是选择正确的重载@Html。ActionLink 这很重要。 我选择了一个不存在的重载(没有最后一个null), MVC没有这样的重载,导致一个错误的URL,类似于OP提到的东西。

个人提示:您可以使用匿名类型并不意味着您可以使用任何重载—这些重载是不存在的?-确定:它必须被定义! -在MVC 5.2时代来到这里