0

ASP.NET MVC4 || C#

I have a MenuRole page which displays list of menu from the database.Users have to select a Role and corresponding menus from the page.All was going well but when i tried to save the data I am getting the following error. 'The request filtering module is configured to deny a request where the query string is too long'.I an using jquery ajax for saving the detaiils and I found out that the parameters are passing as querystring from view to the controller which I think is not an ideal scenario.

Is this the default behaviour of passing data when using jquery ajax in the form?

How can the issue be solved?

error message

enter image description here

Requested URL

enter image description here

JQuery ajax for saving the details

 $("#btnSubmit").click(function () {
            var formData = $('#frmRoles').serialize();
            $.ajax({
                type: "POST",
                url: "@Url.Action("Add","MenuSettings")",
                data: formData,
                datatype: "json",
                success: function (data) {
                    toastr.success(data.message)                        
                },
                error: function (data) {
                    toastr.error(data.message);
                }
            });
        })
3
  • 1
    Do you have a method Add marked with [HttpPost]? Commented Sep 22, 2015 at 7:27
  • @StephenMuecke thanks for your input mate..I decorated the add method with httppost but forgot to decorate the Html form with post method Commented Sep 22, 2015 at 7:37
  • You don't need to decorate the form - its FormMethod.Post by default. And I suspect you must also be doing both the standard submit and the ajax post if that's happening - is $("#btnSubmit") a submit button? - if so add return false; as the last line of the script to cancel the default Commented Sep 22, 2015 at 7:41

1 Answer 1

1

The query string means your making a GET call (and exceeding the query string limit). Assuming you button is a submit button, then your making both a normal submit (the form method must be FormMethod.Get) and the ajax post.

To prevent the default submit, add return false; to the end of your script

$("#btnSubmit").click(function () {
    var formData = $('#frmRoles').serialize();
    $.ajax({
        ....
    });
    return false; // add this
})
Sign up to request clarification or add additional context in comments.

1 Comment

Thats it ... @super steve

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.