I am trying to call from MVC controller application to WEBAPI applicaiton method. I am getting error 405 method not allowed. Its working fine while calling GET and POST.
MVC Applicaiton:
[HttpPost]
public HttpResponseMessage DeleteService(int id) {
//code for webapi
}
WEB API application:
[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);
}
}
Thnaking you. Regards,Sekhar
The methods PUT and DELETE are not allowed by default. You have to allow them in your web applications web.config.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.