Razor actionlink自动生成?URL中的长度= 7?

Pir*_*ada 55 asp.net-mvc razor asp.net-mvc-3 asp.net-mvc-4 asp.net-mvc-5

我在下面的剃刀页面上有链接.

@Html.ActionLink("Create New Profile", "Create", "Profile", new { @class="toplink" })
Run Code Online (Sandbox Code Playgroud)

我看到下面的页面查看源

<a href="/admin/profile/create?length=7" class="toplink">Create New Profile</a>
Run Code Online (Sandbox Code Playgroud)

当我点击链接.URL如下所示.

http://localhost:54876/admin/profile/create?length=7
Run Code Online (Sandbox Code Playgroud)

我不想要?长度= 7.为什么这是自动生成的.

mar*_*ind 88

ActionLink您使用的覆盖匹配(字符串linkText,字符串actionName,Object routeValues,Object htmlAttributes)覆盖.因此,您的"配置文件"值将传递给routeValues参数.此函数关于此参数的行为是获取其上的所有公共属性,并将其添加到用于生成链接的路由值列表中.由于String只有一个公共属性(Length),因此最终会得到"length = 7".

您要使用的正确重载是(字符串linkText,字符串actionName,字符串controllerName,Object routeValues,Object htmlAttributes),并将其称为loke,因此:

@Html.ActionLink("Create New Profile", "Create", "Profile", new {}, new { @class="toplink"})
Run Code Online (Sandbox Code Playgroud)


Mat*_*ker 7

我不确定这个的确切原因,但改为:

@Html.ActionLink("Create New Profile", "Create", "Profile", new {}, new { @class="toplink" })
Run Code Online (Sandbox Code Playgroud)

当你离开最后一个参数(htmlattributes是添加的参数)时,我不知道MVC正在挑选哪个超载,但这将解决它.有一天我会调查并弄清楚到底发生了什么.