0

I am trying to send long string through Ajax. When the "note" string is short, it goes through fine. When it is more than a thousand characters or so, it silently fails, the action method is not called.

Ajax call:

$.ajax({
    url: '@Url.Action("SaveSchoolNote")',
    type: 'POST',
    dataType: 'json',
    data: { schoolId: schoolId, note: note },
    cache: false,

    success: function (data) {
    }
});

Action:

public ActionResult SaveSchoolNote(int schoolId, string note)
{
    ...
}

Please help!

  • 1
    It is most likely due to the MaxJsonLength property. See [here](http://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config). – Rich Andrews Dec 07 '16 at 13:37
  • A thousand characters is not much. Could you try with `data: JSON.stringify({ schoolId: schoolId, note: note }),`? – Win Dec 07 '16 at 14:07
  • combine both properties into an object and post from ajax as a json object – Rudresha Parameshappa Dec 07 '16 at 22:41
  • Set the `contentType` of the ajax properties to `'application/json'`. Right now it's sending it as `'application/x-www-form-urlencoded; charset=UTF-8'` which is likely not what you want. – Heretic Monkey Dec 07 '16 at 22:46
  • Possible duplicate of [How can I use JQuery to post JSON data?](http://stackoverflow.com/questions/6255344/how-can-i-use-jquery-to-post-json-data) – Heretic Monkey Dec 07 '16 at 22:48

0 Answers0