代码改变世界

学习ASP.NET MVC(一):URL ROUTE

2009-04-24 23:22  xiaosuo  阅读(735)  评论(0编辑  收藏  举报
Url Route实例:
            routes.MapRoute(
                
"Default",
                
"{controller}/{action}/{id}",
                
new { controller = "Home", action = "Index", id = 0 },
                
new { action = @"^\w+", id = @"^\d+" }
            );

            routes.MapRoute(
                
"Blog",
                
"Archive/{date}",
                
new { controller = "Blog", action = "Archive" },
                
new { date = @"^\d{4}-\d{2}-\d{2}" }
            );

            routes.MapRoute(
                
"Car",
                
"Car/{make},{model}",
                
new { controller = "Car", action = "Index" },
                
new { date = @"(acural|bmw)" }
            );

            routes.MapRoute(
                
"Book",
                
"Book/Add/{name}",
                
new { controller = "Book", action = "Add" },
                
new { httpMethod = "POST" }
            );

            routes.MapRoute(
                
"CatchIt",
                
"Product/{*values}",
                
new { controller = "Product", action = "Index" }
           );