[英]Web API Put Request generates an Http 405 Method Not Allowed error
[英]HTTP Error 405 Method not allowed while calling web api delete method?
我正在嘗試從MVC控制器應用程序調用到WEBAPI應用程序方法。 我收到錯誤405方法不允許。 調用GET和POST時工作正常。
MVC應用程序:
[HttpPost]
public HttpResponseMessage DeleteService(int id) {
//code for webapi
}
WEB API應用程序:
[HttpDelete]
public HttpResponseMessage DeleteService(int id) {
try {
ServicesModel service = dbContext.Services.Find(id);
IEnumerable<ServicePropertiesModel> serviceProperies = dbContext.ServiceProperties.Where(x => x.ServiceId == id);
if (service != null) {
foreach (ServicePropertiesModel s in serviceProperies) {
dbContext.ServiceProperties.Remove(s);
}
dbContext.Services.Remove(service);
dbContext.SaveChanges();
}
return Request.CreateResponse(HttpStatusCode.OK);
} catch {
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
感動你 問候,Sekhar
默認情況下不允許使用PUT和DELETE方法。 您必須在您的Web應用程序web.config中允許它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.