2

Web Api 2 の属性ルーティングに取り組んでいます。正規表現を含むルートを実装しようとしています

URLはこのようにする必要があります

/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 に答える