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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 21:11:38  来源:igfitidea点击:

ASP.NET MVC routes

c#asp.net-mvc.net-3.5c#-3.0asp.net-mvc-routing

提问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 不需要这是正确的,因为句点不再被忽略对吗?