通过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)
提前感谢您的意见。
答案 0 :(得分:17)
isGroup = @"^(true|false)$"
因此...
routes.MapRoute(
"MenuRouteWithExtension",
"Menu.mvc/{action}/{projectId}/{dealerId}/{isGroup}",
new
{
controller = "Menu",
action = "RedirectUrl",
projectId = "",
dealerId = "",
isGroup = "" //Possibly set this to 'true' or 'false'?
},
new
{
projectId = @"^\d+$",
dealerId = @"^\d+$",
isGroup = "^(true|false)$"
}
);
套管无关紧要,因此应接受True
以及falSE
。
此外,我已将^
和$
放在正则表达式值上,以便它们不匹配,例如blahtrueblah
。