2

I am trying to send a javascript object to my MVC method in VS 2010. Using the VS web server.

    $.ajax({ 
            type: "POST",
            url: "@Url.Action("Filter", "Grid")",
            dataType: "json", 
            data: {"data": JSON.stringify(filtersData) }, 
            contentType: "application/json; charset=utf-8", 
            traditional: true,
            success: function (data) { 
                alert("ok"); 
            },
            error:function (xhr, ajaxOptions, thrownError) { 
                alert(xhr.status); 
                alert(thrownError); 
            }
        }); 

When adding the contentType parameter is causes the 500 error. What am i doing wrong?

tereško
  • 58,060
  • 25
  • 98
  • 150
roywax
  • 63
  • 1
  • 8

2 Answers2

2

This worked in the end:

    var filtersApplyData = GetFiltersApplyData@(Model.PropertyID)();
    var data = JSON.stringify({data: filtersApplyData, classID: @(Model.ClassID)});
    $.ajax({ 
            type: "POST",
            url: "@Url.Action("ApplyFilters", "Grid")",
            data: data, 
            contentType: "application/json", 
            traditional: true,
            success: function (data) { 
                $("#grid").html(data);
            },
            error:function (xhr, ajaxOptions, thrownError) { 
                alert(xhr.status); 
                alert(ajaxOptions); 
                alert(thrownError); 
            }
    }); 
roywax
  • 63
  • 1
  • 8
1

That's very hard to tell from what you have posted.

A 500 error means that the service you called exists but errored processing the data you passed to it.

If you have control over the service (which it sounds like you might based on the title of your question), check its error logs or run your code directly on the server (where typically you will get a more extensive error message). If you don't have any error logging (e.g. no NLog, etc.) check the Windows Event Log.

If you do not have control over the service, inform the person that provides the service that it is producing an error.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • `A 500 error means that the service you called exists but errored processing the data you passed to it.` is what helped me. My controller was being passed the wrong data and was 'rejecting' the request in a sense. – Pat Nov 15 '17 at 23:30