0

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

6
  • Are you facing this issue on your local machine? Commented Apr 14, 2015 at 16:21
  • Why is the delete marked as static? Commented Apr 14, 2015 at 16:28
  • Can you show the code that calls the WebAPI? Why is the WebApi method static? Commented Apr 14, 2015 at 16:30
  • I am changed my code. please find the code for more clarification. Thanks. Commented Apr 14, 2015 at 16:46
  • Where is the section where you are calling the service? Commented Apr 14, 2015 at 16:48

1 Answer 1

1

The methods PUT and DELETE are not allowed by default. You have to allow them in your web applications web.config.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.