Asp.net mvc 4 为什么Web API中的PUT方法后页面url会发生变化?

Asp.net mvc 4 为什么Web API中的PUT方法后页面url会发生变化?,asp.net-mvc-4,asp.net-web-api,Asp.net Mvc 4,Asp.net Web Api,我正在MVC网站中使用WebAPI。这是我在API控制器中的更新操作: public HttpResponseMessage PutProduct(int Id, ProductModel model) { HttpResponseMessage response = null; if (ModelState.IsValid) { model.ProductId = Id; if (model.Update()) r

我正在MVC网站中使用WebAPI。这是我在API控制器中的更新操作:

public HttpResponseMessage PutProduct(int Id, ProductModel model)
{
    HttpResponseMessage response = null;
    if (ModelState.IsValid)
    {
        model.ProductId = Id;
        if (model.Update())
            response = Request.CreateResponse(HttpStatusCode.Created);
    }
    return response;
}
我使用jqajax从Index.cshtml页面中加载的部分视图中调用它。代码工作正常,不会再次调用索引页,而是在局部视图中填充新列表。我不再调用索引页。但是在响应之后,页面url将更改为如下所示:

http://localhost:54820/Products/Index?ProdName=Chicken+Soup&Category=Chinese&Price=20
这是我的AJAX:

function updateprod(product) {
    $.ajax({
        url: uri + '/' + product.ProductId,
        type: 'put',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(product),
        statusCode: {
            201: function (data) { //accepted
                loadlist();
            }
        }
    })
    .fail(function (xhr, textStatus, err) {
        alert(err);
    });
}
我希望URL是这样的,就像它最初的样子:

http://localhost:54820/Products/Index

有人能帮忙吗?

您应该查看响应标题

看来

除此之外,您应该为创建的资源使用201状态代码,对于更新,最好使用200(确定),这是您如何在中读取的

希望能有帮助