webapi请求

Put 更新

Delete 删除

Post 添加

Get 获取

 

当一个控制器里有多个Delete时例如 ProductsController 有一个Delete和DeleteProduct方法,调用 时

 $.ajax({
                type: "DELETE",
                url: "products/" + id,
                success: list()
            });

会报异常{"Message":"发生错误。","ExceptionMessage":"找到了与该请求匹配的多个操作: \r\n类型 WebApi.Controllers.ProductsController 的 System.Collections.Generic.IEnumerable`1[WebApi.Models.Product] Delete(Int32)\r\n类型 WebApi.Controllers.ProductsController 的 System.Collections.Generic.IEnumerable`1[WebApi.Models.Product] DeleteProduct(Int32)","ExceptionType":"System.InvalidOperationException","StackTrace":"   在 System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\r\n   在 System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n   在 System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n   在 System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   在 System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)"}

由此可见webapi是根据请求的type去需找Delete方法的。

posted @ 2015-03-02 11:40  Rookier  阅读(1892)  评论(1编辑  收藏  举报