传递bool的MVC路由约束的有效正则表达式是什么?例如,我有以下路线:
routes.MapRoute("MenuRouteWithExtension","Menu.mvc/{action}/{projectId}/{dealerId}/{isGroup}",new { controller = "Menu",action = "RedirectUrl",projectId = "",dealerId = "",isGroup = "" } new { projectId = @"\d+",dealerId = @"\d+",isGroup = @"???" });
基本上,我需要知道什么是有效的代替???在上面的代码示例中.
这样,另一端的Action可以使用bool类型:
public ActionResult RedirectUrl(int projectId,int dealerId,bool isGroup)
提前感谢您的意见.
解决方法
isGroup = @"^(true|false)$"
所以…
routes.MapRoute( "MenuRouteWithExtension",new { controller = "Menu",isGroup = "" //Possibly set this to 'true' or 'false'? },new { projectId = @"^\d+$",dealerId = @"^\d+$",isGroup = "^(true|false)$" } );
套管应该无关紧要,所以应该接受True,以及falSE.
此外,我已将^和$放在正则表达式值上,以便它们不匹配,例如blahtrueblah.