Question

I am working on Attribute Routing of Web Api 2 . I am trying to implement a Route which contains a regex

Url should be like this

/xyz/sale
/xyz/rent

I tried my best and searched alot on google but in-vane . What i tried is

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

But it gives the following error

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

here is the screenshot of error Error

Please help me out . Thanks

Was it helpful?

Solution

How about:

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

If not try:

[Route("xyz/{Type:regex(^(sale|rent)$)}")]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top