Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to delete all records with checking all checkboxed values. but it is throwing 500 internal server error.

//delete all menu
function performalldeletemenu()
{

    if (confirm('Are you sure you want to delete this menu?'))
    {
        var AllCheckboxes = new Array();
        $("input:checked").each(function () {
            //console.log($(this).val()); //works fine
            AllCheckboxes .push($(this).val());
        });

        $.ajax({
            type: 'DELETE',
            url: '/api/MenuWebApi/DeleteAllMenu/',
            data: { deleteservice: AllCheckboxes },
            success: function (data) {
                if (data.Success == true) {
                    GetMenuList();
                }
            },
            error: function (xhr, textStatus, errorThrown) {
                //window.location = JsErrorAction;
            },
            dataType: "json",
            headers:
            {
                'RequestVerificationToken': JsTokenHeaderValue
            }

        });
    }


    return false;
}

Web-Api Method

public HttpResponseMessage DeleteAllMenu(MenuModel objMenuModel)
        {
}

please if any have done before please let me know.

share|improve this question
add comment

1 Answer

1) Ajax request type should be

 type: 'Post',

2) You Url should be

 url: '/api/MenuWebApi/DeleteAllMenu',
share|improve this answer
 
For Web -Api if delete method then type will be Delete otherwise it is considering 400 Bad Request. so type will be 'Delete' and URL is correct. i have done so many times with single value and it worked this issue is with all checkbox values with array. –  dotnetexpert Aug 13 at 14:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.