我很困惑为什么这个代码

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(linkText: "SomeText", actionName: "SomeAction", controllerName: "SomeControllerName", routeValues: new { parameterName = parameterValue}, htmlAttributes: null)

我解决这个问题的方法是在匿名声明(new{})之前添加一个null到第四个参数,以便它使用以下方法重载:(linkText, actionName, controllerName, routeValues, htmlAttributes):

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

只需删除“Home”(控制器的名称),这样代码将是:

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

请使用五(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", "Home", new { hidefocus = "hidefocus" },null)