title: Return Json from MVC application
body: <p>I'm trying to return Json data from an MVC Application.  I used Fiddler and FireBug to troubleshoot this and the Json data seems to be ok, but for some reason the data still doesn't display.  This is my code:</p>
  
  <pre><code>public class CalendarController : Controller
  {
  
  public JsonResult ReturnCalendarEvents()
          {
  
  
              var model = _service.EventList("JackV", "10/1/2011", "10/8/2011");
              return Json(model, JsonRequestBehavior.AllowGet);
  
  
          }
  
  }
  </code></pre>
  
  <p>Site.Master</p>
  
  <pre><code> $.ajax({
            type: "POST",
            async: false,
            contentType: "application/json; charset=utf-8",
            url: "/Calendar/ReturnCalendarEvents",
            data: "{'UserName':'" + UserName + "','starTime':'" + start.format("isoDateTime") + "','endTime':'" + end.format("isoDateTime") + "'}",
            dataType: "json",
            success: function (result) {
              //Logic goes here
                  },
                                  error: function (e) { alert("An Error Occured" + e); }
                              });
  </code></pre>
  
  <p>So even though in Fiddler I see the actual Json data being returned, in the Site.Master file, this goes straight to the error.  The error returned is [Object object].  Not too helpful.  I debugged my application and there are no errors anywhere before the data is being returned as Json.  Unless the data is not true Json somehow but it sure looks like it.</p>
  
  <p>The weird thing is that the ajax function runs, then goes straight to error, then I step into the Visual Studio code for my controller, then it goes back to this ajax function but this time it does error out, it goes to the success code.  Somewhere along the way, it stops debugging in FireBug and I'm not sure why the data is not being returned.  </p>
  
  <p>Can anybody think of anything that might help me figure this out?  Thank you.</p>
  
  <hr>
  
  <p>Solution:   After I looked at everyone's comments i realized that this line was wrong:</p>
  
  <pre><code>  var schedules = (eval(result.d));
  </code></pre>
  
  <p>This was part of my Success logic that I didn't include in the post.  In FireBug result showed data, but .d was null.  This worked just fine in a web application but it doesn't like the .d in the MVC app.  I changed the code to this and now it works fine.  I still don't know why that function gets hit twice, with the first one erroring out but the 2nd one retrieving the data.  I will look into it more.  </p>
  
  <pre><code> var schedules = (eval(result));
  </code></pre>