用mvc开发了一套系统,有时候难免会从地址栏传递几个参数,这样一来可以看到很清楚看到controler名称和action信息,怎么处理类似京东那样,后缀变成.html格式,小弟学编程不就,感觉这个好高端,那个高手能指点一下!
如果页面很多,还岂不是要填写很多routes.MapRoute()路由规则!
伪静态
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Action1Html", // action伪静态 "{controller}/{action}.html",// 带有参数的 URL new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 参数默认值 ); routes.MapRoute( "IDHtml", // id伪静态 "{controller}/{action}/{id}.html",// 带有参数的 URL new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 参数默认值 ); routes.MapRoute( "ActionHtml", // action伪静态 "{controller}/{action}.html/{id}",// 带有参数的 URL new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 参数默认值 ); routes.MapRoute( "ControllerHtml", // controller伪静态 "{controller}.html/{action}/{id}",// 带有参数的 URL new { controller = "Home", action = "Index", id = UrlParameter.Optional }// 参数默认值 ); routes.MapRoute( "Root", "", new { controller = "Home", action = "Index", id = UrlParameter.Optional });//根目录匹配 routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//默认配置 ); }
大师,谢谢你啊,我还要慢慢研究去,不懂我再来问大师您!
看看路由相关的知识。
http://www.cnblogs.com/John-Connor/archive/2012/04/28/2473911.html
http://www.cnblogs.com/birdshover/archive/2008/01/18/1045008.html
看完后 基本就清楚了吧?
陈大神,好牛逼啊