2

我正在研究 Web Api 2 的属性路由。我正在尝试实现一个包含正则表达式的 Route

网址应该是这样的

/xyz/sale
/xyz/rent

我尽了最大的努力,在谷歌上搜索了很多,但在风向标。我尝试的是

[Route(@"xyz/{Type:^sale|rent$}")]

但它给出了以下错误

The inline constraint resolver of type 'DefaultInlineConstraintResolver' 
was unable to  
resolve the following inline constraint: '^sale|rent$'.

这是错误的屏幕截图 错误

请帮帮我。谢谢

4

1 回答 1

3

怎么样:

[Route("xyz/{Type:regex(sale|rent)}")]

如果不尝试:

[Route("xyz/{Type:regex(^(sale|rent)$)}")]
于 2013-11-18T15:49:47.063 回答