MVC的路由设置【转】
时间:2014-04-30 17:41:59
收藏:0
阅读:426
转,MVC的路由设置。
后端获取路由里面action的参数,函数需要设置相同的参数名称才行。
routes.MapRoute( "Default", "{controller}/{action}/{id}", new { action = "Index", id = "0" }, new { controller = @"^\w+", action = @"^\w+", id = @"^\d+" }); // Archive/2008-05-07 routes.MapRoute( "BlogArchive", "Archive/{date}", new { controller = "Blog", action = "Archive" }, new { date = @"^\d{4}-\d{2}-\d{2}" }); // Car/bmw.abc routes.MapRoute( "Car", "Car/{make}.{model}", new { controller = "Car", action = "Index" }, new { make = @"(acural|bmw)" }); //必须是提交post url直接回车是get routes.MapRoute( "Book", "Book/Add/{name}", new { controller = "Book", action = "Add" }, new { httpMethod = "POST" }); //后面所有东西都捕获 routes.MapRoute( "CatchIt", "Product/{*values}", new { controller = "Product", action = "Index" });
评论(0)