C# ASP.NET MVC 路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/276766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET MVC routes
提问by Nesizer
I need help with this route map
我需要有关此路线图的帮助
routes.MapRoute("Blog_Archive",
"Blog/Archive/{year}/{month}/{day}",
new {
controller = "Blog",
action = "archive",
year = "",
month = "",
day = "",
page = 0
});
When I call http://localhost:5060/blog/Archive/2008/11, it picks up the year and month and sends it to the controller. But when I try http://localhost:5060/blog/Archive/2008
it sends it to the controller but the year parameter is null and so are all the other parameters.
当我调用http://localhost:5060/blog/Archive/2008/11 时,它会获取年份和月份并将其发送到控制器。但是当我尝试http://localhost:5060/blog/Archive/2008 时,
它会将它发送到控制器,但 year 参数为空,所有其他参数也是如此。
采纳答案by Michael Stum
Do you have any other Route for Blog/Archive/{something}?
你有博客/档案/{something}的其他路线吗?
Use the Routing Debuggerto see which route actually gets hit, most likely it's not hitting that route.
使用路由调试器查看实际命中了哪条路由,很可能它没有命中该路由。
回答by Mouffette
Subnus, I noticed in your code that you have routes.IgnoreRoute("favicon.ico"); I don't think this is required with MVC 1.0 right because the period is no longer ignored correct?
Subnus,我在你的代码中注意到你有 routes.IgnoreRoute("favicon.ico"); 我认为 MVC 1.0 不需要这是正确的,因为句点不再被忽略对吗?