0

trying to return dictionary as jsonresult, number of elements in dictionary > 3.6k; my code:

$('#go').click(function () {
      $("#content").empty().html('<img src="Content/loading.gif" style="top:100px;left:100px;"/>');
      $.ajax({
          type: 'POST',
          url: '<%= Url.Action("LoadContent","Home") %>',
          async: true,
          data: {
              block: $('input[name=block]:checked').attr('value'),
              type: $('input[name=type]:checked').attr('value'),
              begin: $('#begindate').attr('value') + " " + $('#begintime').attr('value'),
              end: $('#enddate').attr('value') + " " + $('#endtime').attr('value')
          },
          dataType: 'json',
          success: function (response) {
              alert(response);
              $.plot($("#content"), repsonse);
          }
      });
  });

and server side:

public JsonResult LoadContent(string block,string type,string begin,string end) {
        List<FinalResult> result = Core.LetThePartyBegin(DateTime.Parse(begin), DateTime.Parse(end), block);
        Dictionary<DateTime, double> returnValue = new Dictionary<DateTime, double>();
        result.ForEach(p =>
            p.Result.ForEach(q => returnValue.Add(p.Datetime + new TimeSpan(0, 0, q.Number), q.W)));
        return Json(returnValue);
    }

so, Json(returnValue) contains 3600 values, and i'm getting error 500 internal server error; if i set Json(returnValue.Take(100)) it works. is there any constraint on size of jsonresult?

eba
  • 673
  • 2
  • 11
  • 22
  • can you provide start20 and end 20 chracters of json returned, it might help locating the error. – Furqan Hameedi Feb 24 '11 at 11:57
  • how?? its simple dictionary, dunno what to show – eba Feb 24 '11 at 12:00
  • what is the details of the error? – roryf Feb 24 '11 at 12:38
  • See @David Murdoch's answer [here](http://stackoverflow.com/questions/1151987/can-i-set-an-unlimited-length-for-maxjsonlength-in-web-config/7207539#7207539) For some reason MS chose not to follow the web config setting for JsonResult ... – Adam Sep 06 '12 at 15:17

2 Answers2

1

There is a max size for an ajax response. (I'm not sure but I think it's 4M)

Maybe your intended response might be larger than this maximum. This would also explain why it works when you return a subset smaller than the max size.

Check the detailed error message

Fabiano
  • 5,124
  • 6
  • 42
  • 69
0

One of you dates is not parsing. Are you sure they are all valid?

ctrlShiftBryan
  • 27,092
  • 26
  • 73
  • 78