Razor actionlink 自动生成 ?length=7 在 URL 中? [英] Razor actionlink autogenerating ?length=7 in URL?

查看:30
本文介绍了Razor actionlink 自动生成 ?length=7 在 URL 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在剃刀页面上有以下链接:

I have the link below on a razor page:

@Html.ActionLink("Create New Profile", "Create", "Profile", new { @class="toplink" })

在查看源页面出现如下图:

It appears in thes source of view page as shown below:

<a href="/admin/profile/create?length=7" class="toplink">Create New Profile</a>

当我点击链接时,网址是这样的:

When I click on the link the URL is like this:

http://localhost:54876/admin/profile/create?length=7

我不想要 ?length=7.为什么会自动生成这个?

I don't want ?length=7. Why is this auto generated?

推荐答案

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

The ActionLink override you are using matches to the (string linkText, string actionName, Object routeValues, Object htmlAttributes) override. So your "Profile" value is being passed to the routeValues parameter. The behavior of this function with respect to this parameter is to take all public properties on it and add it to the list of route values used to generate the link. Since a String only has one public property (Length) you end up with "length=7".

您要使用的正确重载是 (string linkText, string actionName, string controllerName, Object routeValues, Object htmlAttributes) 你这样称呼它:

The correct overload you want to use is the (string linkText, string actionName, string controllerName, Object routeValues, Object htmlAttributes) and you call it loke so:

@Html.ActionLink("Create New Profile", "Create", "Profile", new {}, new { @class="toplink"})

这篇关于Razor actionlink 自动生成 ?length=7 在 URL 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆