标签:style blog http io ar color os sp for
组件下载地址 haacked.com
1、在mvc项目中引入组件
2、配置route规则
public static void RegisterRoutes(RouteCollection routes) { //routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //忽略About页面,不能将它已到mapRoute后面,改方法不是有Route组件提供是System.Web.Mvc下的方法 //routes.IgnoreRoute("Home/About"); routes.MapRoute( "Default", // 路由名称 "{controller}/{action}/{id}", // 带有参数的 URL new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // 参数默认值 new { controller=@"^\w+",action=@"^\w+"} ); routes.MapRoute( "Filter", // 路由名称 "{controller}/{action}/{id}", // 带有参数的 URL new { controller = "Filter", action = "Index", id = UrlParameter.Optional }, // 参数默认值 new { controller = @"^\w+", action = @"^\w+" } ); routes.MapRoute( "car", "Car/{make}/{pro}", new {controller="Car",action="Index",id=1} ); routes.MapRoute( "Archive", "Archive/{date}", new { controller = "blog", action = "Archive" }, new {date=@"^\d{4}-\d{2}-\d{2}" } ); routes.MapRoute( "Book", "Book/Add/{name}", new { controller = "Book", action = "Add" }, new { HttpMethod="Post"} ); routes.MapRoute( "Product", "Product/{*value}",//*表示匹配一切内容 new {controller="Product",action="Index" } ); /*Dictionary<string, object> defaultRout = new Dictionary<string, object>(); defaultRout["action"] = "Index"; defaultRout["id"] = 0; RouteValueDictionary defaultRouteValue = new RouteValueDictionary(defaultRout); RouteValueDictionary constrainRouteValue = new RouteValueDictionary(); constrainRouteValue["controller"] = @"\w+"; constrainRouteValue["id"] = @"\d+"; Route route = new Route("{controller}/{action}/{id}", defaultRouteValue, constrainRouteValue, new MvcRouteHandler());*/ }
3、在Global.asax.cs代码中写入
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
//设为true表示url指向磁盘上的物理文件也会进行url routing处理,例如一个普通的html页面
RouteTable.Routes.RouteExistingFiles = true;
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}
标签:style blog http io ar color os sp for
原文地址:http://www.cnblogs.com/ZJ199012/p/4155431.html