MVC3 controller returns JsonFile

I have a problem with json result. When called from jquery, it returns the file to be saved, instead of executing the success function. A get jquery request occurs in the document.ready function.

Any help would be appreciated.

public ActionResult Locations()
    {
        LocationsModel lm = new LocationsModel();
        return Json(lm.getPins(), JsonRequestBehavior.AllowGet);
    }

I also tried:

public JsonResult Locations()
    {
        LocationsModel lm = new LocationsModel();
        return Json(lm.getPins(), JsonRequestBehavior.AllowGet);
    }

jquery looks like this:

$.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: this.href,
        data: "{}",
        dataType: "json",
        success: function (msg) { getPins_success(msg); },
        error: OnError
    });

Thank you, Chris

Edit:

It doesn’t matter that it was a spirit. As soon as I moved the json request to another action in the controller and loaded the view, it all worked. Now I have problems with parsing, but this is another problem.

+5
source share
1 answer

you must use getJson .

For you, it will be:

$.getJSON(this.href, function (msg) { getPins_success(msg); });

This will allow you to parse the returned data as json.

+1

All Articles