MVC3 Controller returning JsonFile [closed]
I am having a problem with a json result. When calling from the jquery it is returning a file to be saved instead of executing the success function. The 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 have also tried:
public JsonResult Locations()
{
LocationsModel lm = new LocationsModel();
return Json(lm.getPins(), JsonRequestBehavior.AllowGet);
}
The jquery is as follows:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: this.href,
data: "{}",
dataType: "json",
success: function (msg) { getPins_success(msg); },
error: OnError
});
Thanks, Chris
Edit:
Never mind it was a duh. Once I moved the json request to another action in the controller and loaded the view it all worked out. Now I am having parsing problems but that is another issue all together.
you should use getJson instead.
For you it would be:
$.getJSON(this.href, function (msg) { getPins_success(msg); });
This will let you parse the return data as json.
精彩评论