私はという名前のコントローラーを持っています
Products と i には 3 つのアクションがあります
- Product : int を受け取り、モデル (クラス) オブジェクトを返します
- カテゴリ:文字列を受け取り、モデル (クラス) オブジェクトの配列を返します
- すべて:モデル (クラス) オブジェクトの配列を返すパラメーターはありません
私が試していたのは、次のマッピングでした
製品-> api / 製品 / 製品 / 1
カテゴリ-> api / 製品 / カテゴリ / ソース
すべて-> api / 製品 / すべて
アクションの名前はURL構造をサポートしているので、一般的なルートを試していました
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
他のすべては機能していますが、このhttp://localhost:2271/api/products/category/2
URLを使用すると次のエラーが発生します
<Error>
<Message>
No HTTP resource was found that matches the request URI 'http://localhost:2271/api/products/category/2'.
</Message>
<MessageDetail>
No action was found on the controller 'Products' that matches the request.
</MessageDetail>
</Error>
一方、この URL api/products/category/?cat=abc
&api/products/category?cat=abc
は正常に機能しています...... [cat は受信パラメータ名です]
ヘルプ !!!