如何让 Html.ActionLink 返回非查询字符串链接?
每当我使用 Html.ActionLink 它总是给我参数作为?而不是将其作为 url 的一部分。
例如:
@Html.ActionLink("Edit", "Edit", new { Username = (string)item.username })
给我:
/Edit?Username=username
而不是:
/Edit/Username
就像我在控制器中定义的那样。
谁能告诉我如何走另一条路?而不是的方式。
谢谢
whenever I use Html.ActionLink it always gives me the parameter as ? instead of it being apart of the url.
For example:
@Html.ActionLink("Edit", "Edit", new { Username = (string)item.username })
Gives me:
/Edit?Username=username
Instead of:
/Edit/Username
like I have it defined in my controller.
Can anyone tell me how to get the other way? The instead of way.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要在
global.asax
中注册一个路由来定义您的Username
参数:You probably need to register a route in
global.asax
to define yourUsername
parameter:我使用 AttributeRouting 来处理这些事情,用它你可以用实际路径装饰你的控制器,如下所示:
I use AttributeRouting for these things, with it you can decorate your controller with the actual path, like so: