从零编程:MVC路由中快速定向——MapRoute()

 

在RouteProvider中编写多个MapRoute()可以提高网页响应的速度,让路由直接定位到相应的Action和View;

 下面将讲解MapRoute()方法:

1
routes.MapRoute("WidgetsByZone",//路由的名称 2 "widgetsbyzone/", 3 new { controller = "Widget", action = "WidgetsByZone" }, 4 new[] { "Nop.Web.Controllers" });//带有参数的 URL

使用路由访问本地文件:
1 routes.RouteExistingFiles = true; 
2 
3 routes.MapRoute("DiskFile", "Content/StaticContent.html", new { controller = "Customer", action = "List", });

最多参数的重载:

1 public static Route MapRoute(
2     this RouteCollection routes,
3     string name,//路由在路由列表里的唯一名字(两次MapRoute时name不能重复)
4     string url,//路由匹配的url格式
5     Object defaults,
6     Object constraints,//url的 {占位符} 的约束
7     string[] namespaces//跨命名空间
8 )

 


posted @ 2015-08-13 22:40  小小小小小鸟  阅读(182)  评论(0编辑  收藏  举报