创建 ActionLink,同时仍保留原始 Uri/路由值
我有一个带有默认索引操作的控制器,以及许多其他操作,每个操作都呈现自己的视图。
当一个操作方法调用另一个操作时,浏览器中的 Uri 类似于
http://localhost/Home/Events /20100120/Sydney
例如,我如何在像这样的模板之一中创建操作链接,同时仍然保留其他路由值? http://localhost/Home/Events/20100120/Sydney/10PM
如果我这样做,我丢失了 Uri 中的所有其他路由值。
<%= Html.ActionLink("View 10PM times", "Events", "Home", new Dictionary<string, object>() { {"time", "10PM"} })%>
I have a controller with a default Index action, as well as many other actions each rendering their own view.
When an action method calls another action, the Uri in the browser is something like
http://localhost/Home/Events/20100120/Sydney
How would I create an Action Link in one of my templates like this for example, and still preserve the other route values?
http://localhost/Home/Events/20100120/Sydney/10PM
If I do this, I lose all the other route values in the Uri.
<%= Html.ActionLink("View 10PM times", "Events", "Home", new Dictionary<string, object>() { {"time", "10PM"} })%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
路线数据会自动保存。假设您有以下路由:
现在您请求
/foo/t1/t2/Action1
并在视图中写入一个指向Action2
的链接:将生成以下 url :
/foo/t1/t2/Action2
。路由值被保留。Route data is automatically preserved. Suppose that you have the following route:
Now you request
/foo/t1/t2/Action1
and inside the view you write a link toAction2
:The following url will be generated:
/foo/t1/t2/Action2
. Route values are preserved.您可以像这样使用 Html.RouteLink() :
You can use the Html.RouteLink() like so: