MVC 3 路由 - 单操作路由
我有一个关于同一控制器中的路由/导航的问题。
假设我有以下路由设置
routes.MapLowercaseRoute("SomeAwesomeControllerLookup",
"SomeAwesomeController/{genre}/{region}/{lookup}",
new
{
controller = "SomeAwesomeController",
action = "Index",
genre = UrlParameter.Optional,
region = UrlParameter.Optional,
lookup = UrlParameter.Optional,
});
和 Url 操作,如下所示,
<a href="@Url.Action("Index", "SomeAwesomeController", new { genre = "Movies" })">Movies</a>
我希望我的 URL 每次都看起来像“/someawesomecontroller/movies”,但是当我导航到像“/someawesomecontroller/movies/boston”这样的过滤 URL 时/today”我的菜单 URL 仍然是“/someawesomecontroller/movies/boston/today”,无论上面的 HTML 片段中指定的参数如何。
我可以确保呈现的 URL 始终为“/someawesomecontroller/movies”,而无需对其进行硬编码吗?
I've got a question about routing / navigation with-in the same controller.
Lets say I've got the following route setup
routes.MapLowercaseRoute("SomeAwesomeControllerLookup",
"SomeAwesomeController/{genre}/{region}/{lookup}",
new
{
controller = "SomeAwesomeController",
action = "Index",
genre = UrlParameter.Optional,
region = UrlParameter.Optional,
lookup = UrlParameter.Optional,
});
And a Url Action as follows
<a href="@Url.Action("Index", "SomeAwesomeController", new { genre = "Movies" })">Movies</a>
I would expect my URL's to look like "/someawesomecontroller/movies" every time however when I've navigated to a filtered URL like "/someawesomecontroller/movies/boston/today" my menu URL's remain "/someawesomecontroller/movies/boston/today" regardless of the parameters specified in the HTML snipped above.
I can ensure the URL rendered is always "/someawesomecontroller/movies" without hard-coding it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我其他时候了解到的,路由值被过滤并由动作渲染器使用。
应该解决你的问题。 (也可以尝试“null”,但我相信这不会覆盖现有的路由值。
As I learnt some other time, the route values are filtered down and used by the Action renderer.
Should fix your problem. (Could also try "null", but I believe that won't override the existing route values.