asp.net的MVC Html.ActionLink()保持航线价值,我不想 [英] asp.net mvc Html.ActionLink() keeping route value I don't want
问题描述
我有以下的ActionLink在我看来
I have the following ActionLink in my view
<%= Html.ActionLink("LinkText", "Action", "Controller"); %>
和它创建下列网址 http://mywebsite.com/Controller/Action
说我在末尾加上一个ID像这样: http://mywebsite.com/Controller/Action/53和导航到该页面。在这个页面上我有我上面指定的标记。现在,当我在看的URL它创建它看起来像这样:
Say I add an ID at the end like so: http://mywebsite.com/Controller/Action/53 and navigate to the page. On this page I have the markup I specified above. Now when I look at the URL it creates it looks like this:
http://mywebsite.com/Controller/Action/53 (注意添加了ID的)
http://mywebsite.com/Controller/Action/53 (notice the addition of the ID)
但我想它删除ID和看起来像它做最初,这样的 http://mywebsite.com/Controller/Action (注意这里没有ID)
But I want it to remove the ID and look like it did originally, like this http://mywebsite.com/Controller/Action (notice no ID here)
任何想法我怎么能解决这个问题?我不想因为我的控制器/动作可能会更改为使用硬codeD的URL。
Any ideas how I can fix this? I don't want to use hard coded URLs since my controller/actions may change.
推荐答案
解决方案是用户自己指定的路线值(低于第三个参数)
The solution is to specify my own route values (the third parameter below)
<%= Html.ActionLink("LinkText", "Action", "Controller",
new { id=string.Empty }, null) %>
这篇关于asp.net的MVC Html.ActionLink()保持航线价值,我不想的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!