码迷,mamicode.com
首页 > Windows程序 > 详细

webapi请求

时间:2015-03-02 12:43:21      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:

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方法的。

webapi请求

标签:

原文地址:http://www.cnblogs.com/smailxiaobai/p/4308371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!