使Regex用于完全匹配的两个字符串单词
-
26-12-2019 - |
题
我正在研究Web API 2的属性路由。我正在尝试实现一个包含Regex
的路由URL应该是这样
/xyz/sale
/xyz/rent
.
我尽我所能并在谷歌上搜索很多东西,但vent。我尝试过的是
[Route(@"xyz/{Type:^sale|rent$}")]
.
但它给出了以下错误
The inline constraint resolver of type 'DefaultInlineConstraintResolver'
was unable to
resolve the following inline constraint: '^sale|rent$'.
.
这是错误的屏幕截图
请帮帮我。谢谢
解决方案
怎么样:
[Route("xyz/{Type:regex(sale|rent)}")]
.
如果不是尝试:
[Route("xyz/{Type:regex(^(sale|rent)$)}")]
. 不隶属于 StackOverflow