对于一个场景,我有一个ASP.NET MVC应用程序,其URL包含以下内容:
http://example.com/Customer/List http://example.com/Customer/List/Page/2 http://example.com/Customer/List http://example.com/Customer/View/8372 http://example.com/Customer/Search/foo/Page/5
这些URL是通过Global.asax.cs中的以下路由实现的
routes.MapRoute( "CustomerSearch","Customer/Search/{query}/Page/{page}",new { controller = "Customer",action = "Search" } ); routes.MapRoute( "CustomerGeneric","Customer/{action}/{id}/Page/{page}",new { controller = "Customer" } ); //-- Default Route routes.MapRoute( "Default","{controller}/{action}/{id}",action = "Index",id = "" } );
这些都很顺利,直到新的要求到达,并希望将关键字“客户”从网址中删除,以使URL看起来像:
http://example.com/List http://example.com/List/Page/2 http://example.com/List http://example.com/View/8372 http://example.com/Search/foo/Page/5
编辑:更正示例链接,感谢@haacked.
我试图添加新的MapRoutes来采取{action},并将默认控制器设置为Customer.例如/
routes.MapRoute( "CustomerFoo","{action}",action = "Index" } );
这似乎工作,但是现在Html.ActionLink()生成的所有链接都是奇怪的,不再是URL友好的.
那么这是可以实现的吗?我正走向正确吗?