Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 为什么我的MVC actionlink会将我带到带有长度查询字符串值的URL?_Asp.net Mvc_Actionlink - Fatal编程技术网

Asp.net mvc 为什么我的MVC actionlink会将我带到带有长度查询字符串值的URL?

Asp.net mvc 为什么我的MVC actionlink会将我带到带有长度查询字符串值的URL?,asp.net-mvc,actionlink,Asp.net Mvc,Actionlink,关于这一点,我真的无能为力 简单地说,我试图呈现以下链接: <a class="button active-button" href="/Home/Register">Register</a> <a class="button active-button" href="/Home/Register?Length=4">Register</a> 它呈现了这个链接: <a class="button active-button" href="

关于这一点,我真的无能为力

简单地说,我试图呈现以下链接:

<a class="button active-button" href="/Home/Register">Register</a>
<a class="button active-button" href="/Home/Register?Length=4">Register</a>
它呈现了这个链接:

<a class="button active-button" href="/Home/Register">Register</a>
<a class="button active-button" href="/Home/Register?Length=4">Register</a>


我不明白QueryString值是从哪里来的,所以我犯了什么错误?

之所以发生这种情况,是因为您调用了
ActionLink的错误重载

@Html.ActionLink("Register", "Register", "Home", null, new { @class = "button active-button" }) 

这是由于另一个答案中提到的错误重载造成的。如果您对应该使用哪个重载感到困惑,则可以使用visual studio intellisence

MVC3+
中,您有这个

Html.ActionLink("Register", 
                "Register",   // <-- ActionMethod
                "Home",  // <-- Controller Name.
                 null, // <-- Route arguments..you don't need this
                new {@class = "button active-button"}// <-- htmlArguments
                )
Html.ActionLink(“注册”,

“Register”,//我以为是,但不知道还能做什么……self注意:正确地学习razor:/无论如何,谢谢:)添加了空值,它可以完美地工作