KunalKumar
KunalKumar

Reputation: 45

MVC (Razor) Json error (500 internal server error)

Controller Action is:

    public ActionResult GetStatesByCountry(string countryCode)
    {
        return Json(DropDownHelper.GetState(countryCode).Select(x => new { value = x.Code, text  x.Name }));
    }

When I Debug using firebug, I got following error.

This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.

Upvotes: 2

Views: 1539

Answers (2)

Zabavsky
Zabavsky

Reputation: 13640

You have to add JsonRequestBehavior.AllowGet to the method, because the default value is DenyGet:

public ActionResult GetStatesByCountry(string countryCode)
{
    return Json(DropDownHelper.GetState(countryCode).Select(x => new { value = x.Code, text  x.Name }), JsonRequestBehavior.AllowGet);
}

Upvotes: 1

Amit Mishra
Amit Mishra

Reputation: 431

Use JsonRequestBehavior.AllowGet

return Json(DropDownHelper.GetState(countryCode).Select(x => new { value = x.Code, text = x.Name }), JsonRequestBehavior.AllowGet);

Upvotes: 3

Related Questions