开发者

MVC3 Controller returning JsonFile [closed]

开发者 https://www.devze.com 2023-04-10 03:51 出处:网络
This question is unlikely to help any future开发者_如何学Python visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is n
This question is unlikely to help any future开发者_如何学Python visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消