Put 更新web
Delete 刪除ajax
Post 添加api
Get 獲取url
當一個控制器裏有多個Delete時例如 ProductsController 有一個Delete和DeleteProduct方法,調用 時spa
$.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)"}code
因而可知webapi是根據請求的type去需找Delete方法的。blog