2
我想建立一个具有正常CRUD操作的控制器的路由,但希望详细信息操作不在URL中显示'详细信息'。计算器似乎有这种类型的路由配置:如何删除MVC URL路由中的'Details',但保持其他操作不变?
http://stackoverflow.com/questions/999999/
http://stackoverflow.com/questions/ask
使用这个比喻,我的路线目前是这样的:
http://stackoverflow.com/questions/Details/999999/
通过将以下途径我能得到Details
删除:
routes.MapRoute("Q1", "questions/{id}",
new { controller = "Questions", action = "Details" });
但是,拉起控制器上的其他动作(例如本例的/questions/new
)是抱怨无法解析id。
有没有一种方法来设置路由,以便我不必手动输入所有其他操作(MapRoute“items/create”,“items/delete”等)到Global.asax中的.cs?我基本上是想有一个像第二条路线:
routes.MapRoute("Q2", "questions/{action}",
new { controller = "Questions", action = "Index" });
...并具备路由引擎使用路线Q1如果{id}
整数匹配,并且{action}
如果它是一个字符串。这可能吗?
这工作完美。但请注意,约束条件需要读作@“\ d +”。 – Jason 2009-06-16 13:16:20