Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have got the following on an API controller:

public void UpdateClient(Client client)
    {
        try
        {
            if (ModelState.IsValid)
            {
                db.Entry(client).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
        catch
        {
            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
        }
    }

And the following on the page:

$.ajax({
            url: "api/client/UpdateClient",
            type: "PUT",
            contentType: 'json',
            data: ko.toJSON(model.selectedClient()),
            success: function (result) {
                getClients();
                $("#loader").hide();
            },
            failure: function (result) {
                alert(result.d);
                $("#loader").hide();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("An error occurred, please try again.");
                $("#loader").hide();
            }
        });

But this gives the error 405 Method Not Allowed, can anyone see where I may have gone wrong? For reference the url for the api is ok as I use the same api controller for other functions too.

Also the selectedClient() is a Client object received via WebApi so should match perfectly to PUT up again.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
873 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you are using IIS7 and have WebDav installed, try removing it. I was getting the same error only with the PUT verb and it solved the issue

Update: You can read about WebDav here: http://www.iis.net/learn/get-started/whats-new-in-iis-7/what39s-new-for-webdav-and-iis-7


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...