Sean Anderson
Sean Anderson

Reputation: 29301

Returning JsonResult is giving Server 500 error?

First attempt at MVC. Attempting to return a JsonResult. I have this in my controller:

[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetHistoricalReports()
{
    JsonResult result = Json("test");
    //JsonResult result = Json(DashboardSessionRepository.Instance.HistoricalReports);

    return result;
}

and in my view:

function OnHistoricalListBoxLoad(historicalListBox) {
    $.getJSON('GetHistoricalReports', function (data) {
        alert(data);
    }

I have a break-point set inside of GetHistoricalReports and it is indeed being hit. The alert in OnHistoricalListBoxLoad never displays, however.

Upvotes: 3

Views: 1676

Answers (1)

John Kalberer
John Kalberer

Reputation: 5790

You need to return your result like:

return Json("test", JsonRequestBehavior.AllowGet)

Upvotes: 6

Related Questions