私はMVCを初めて使い、MVCにウェブアプリケーションを書いています。私は取得リクエストを送信しようとしています。
私がリクエストを送信しようとしているから、かみそりのページ持っている:リクエストを送信しない
$(document).ready(function() {
var query = $('#productQuery').val();
alert("Start.");
var uri = 'api/search/products?q=abc';
$.get(uri, function (data) {
alert("Load was performed.");
});
});
を
[RoutePrefix("api/search")]
public class SearchController : ApiController
{
[Route("products")]
[HttpGet]
public async Task<IEnumerable<ProductDocument>> searchProducts(
[FromUri(Name = "q")]string query,
[FromUri(Name = "cat")]string[] categories=null)
{
ProductsResponse response = await SolrWebApi.QueryAsync<ProductsResponse>(query);
if (response.Header.Status != 0)
{
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
return response.Body.Documents.Take(3).ToArray();
}
誰かが私が間違っていることを教えてもらえれば幸いであり、なぜ私の取得リクエストは送信されないのでしょうか?
あなたのuriは、ルーティング属性を与えられた 'api/search/products'でなければなりません。 '@ Url.Action'を調べると、ルートをハードコードするのではなく、コントローラ+アクション経由でURLを取得することができます。それでも動作しない場合は、 'categories'パラメータなしで(またはパラメータをゼロにしてビルドして)試してください。 –