日期:2014-05-18  浏览次数:20363 次

【求解答】MVC路由怎么配置带参数的URL?
我再MVC中使用了一部分WebForm页面,我想把WebForm的URL通过路由的方式转换成更易理解记忆的格式。如:
Assembly code
/webpage/admin/index.aspx?Section=Merchant&Pages=CreateWays&Number=Spt1

转换为
Assembly code
/admin/index/Merchant/CreateWays/Spt1


我谷歌了一下,可以通过写IRouteHandler继承类完成如下的转换:
C# code
routes.Add(new Route("web/{page}",new WebFormsRouteHandler()));

Assembly code
/WebForms/Default.aspx

转换为
Assembly code
/web/Default


但是我需要带参数的转换应该怎么写啊,MVC路由参数都有哪些,怎么自定义路由参数啊?
求高手解答

------解决方案--------------------
你看一下global.asax,你看一下他那个怎么写,你应该会有点启发
他是这么写的routes.MapRoute(
"Default", // 路由名称
"{controller}/{action}/{id}", // 带有参数的 URL
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
其实你可以模仿啊,对他进行修改
------解决方案--------------------
一般来说最简单的方法是URLRewirte