Ajax request for asp.net mvc controller returning 500 - internal server error

I have two selecton view:

<select class="input-sm form-control input-s-sm inline" onchange="carregarCidades()" id="comboEstado">
    ...
</select>

<select class="input-sm form-control input-s-sm inline" id="comboCidade">
   ...
</select>

The first represents the state, and when I select it, I want to execute a function carregarCidadesto load the cities of this stat, and they load them into another select. Here is the function:

function carregarCidades() {
    var url = "@Url.Action("CarregarCidades", "Usuario")";

    var estado = $("#comboEstado").find(":selected").text();

    $.get(url, { pEstado: estado }, function (cidades) {
        $("#comboCidade").html(""); // clear before appending new list 
        $.each(cidade, function (i, cidade) {
            $("#comboCidade").append(
                $('<option></option>').val(cidade.id_cidade).html(cidade.cidade));
        });
    });
}

Now, here is the CarregarCidades action in the UsuarioController:

public ActionResult CarregarCidades(string pEstado)
{
    string cCidades = oVFP.BuscaCidade(pEstado);

    DataSet dsC = new DataSet();
    dsC.ReadXml(new StringReader(cCidades));

    JsonResult result = Json(dsC.Tables["curretorno"]);
    return result;
}

I am debugging the action and, apparently, everything is in order:

enter image description here enter image description here

But after Action returns the Json result, the callback function is not called in jQuery code, and I got 500 internal server errors in my console.

+4
source share
2 answers

JsonAllowRequestbehavior AllowGet, DenyGet:

JsonResult result = Json(dsC.Tables["curretorno"],JsonRequestBehavior.AllowGet);

.

+4

, [WebMethod] .

, , - Json :

return Json(result, JsonRequestBehavior.AllowGet);

, , 500.

Edit:

[WebMethod] .

+1

All Articles