asp.net-mvc – bool的MVC Route Constraint

传递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.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....