检查除 space 以外的任何字符串 - MVC 路由
Check any string except space - MVC routing
使用此代码,我们只强制检查数字:
routes.MapRoute("ById", "{id}", new { controller = "Home", action = "ViewById"}, new{id = @"\d+"});
我看到很多关于没有 space 的字符串的答案,但其中 none 适用于 MVC 路由。
正在寻找正则表达式,在这种情况下,我是对的:
"д_test.8_.は_any_language_without.Space"
并在以下情况下给我假:
"a b"
希望这就是您要找的
routes.MapRoute(
name: "aaaaa",
url: "{id}",
defaults: new { controller = "pages", action = "view" },
constraints: new { id = @"^[a-zA-Z0-9\w]*$" } //*********this should work**
);
使用此代码,我们只强制检查数字:
routes.MapRoute("ById", "{id}", new { controller = "Home", action = "ViewById"}, new{id = @"\d+"});
我看到很多关于没有 space 的字符串的答案,但其中 none 适用于 MVC 路由。
正在寻找正则表达式,在这种情况下,我是对的:
"д_test.8_.は_any_language_without.Space"
并在以下情况下给我假:
"a b"
希望这就是您要找的
routes.MapRoute(
name: "aaaaa",
url: "{id}",
defaults: new { controller = "pages", action = "view" },
constraints: new { id = @"^[a-zA-Z0-9\w]*$" } //*********this should work**
);