gpt4 book ai didi

asp.net-mvc - boolean 的MVC路线约束

转载 作者:行者123 更新时间:2023-12-04 05:34:02 25 4
gpt4 key购买 nike

对于通过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",
"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)$"
}
);

大小写无关紧要,因此 TruefalSE也应被接受。

另外,我将 ^$放在正则表达式值上,以使它们不匹配,例如 blahtrueblah

关于asp.net-mvc - boolean 的MVC路线约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2059141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com