【问题标题】:getJSON loses the controller in the path on second requestgetJSON 在第二次请求时丢失路径中的控制器
【发布时间】:2019-08-03 05:25:25
【问题描述】:

我有一个从另一个加载 DDL 的 getJSON。 但是第一次加载时,它做得很好。当我在页面上提交时,在控制台上我在 getJSON 上收到错误 404,当我双击它时,它会向我发送 getJSON 但没有控制器 视觉解释:

功能:

function showPuestoEdit(val, index) {
$.getJSON("GetPuestosCargaJSON" + "?value=" + val, function (result) {
    // Cleans the DDL first
    $("#ddlPuesto").empty();
    var data = result.data;

    for (var i = 0; i < data.length; i++) {
        $("#ddlPuesto").append("<option value=" + data[i].id_puesto + ">" + data[i].nombre + "</option>")
    }
    // This is in order to set the second ddl in the correct position
    $("#ddlPuesto").val(index);
}); }

我的控制器 [Usuario]:

    public JsonResult GetPuestosCargaJSON(int? value)
    {
        // Carga los puestos dependiendo del departamento
        List<Puesto> list = repo.GetReaderFromStringToList<Puesto>("SOME SELECT * FROM QUERY HERE where some_id = " + value);
        return Json(new { data = list }, JsonRequestBehavior.AllowGet);
    }

控制台中的第一个请求:

http://localhost:10994/Usuario/GetMunicipiosCargaJSON?value=17

但是当我提交一些信息并想再试一次时,请求是:

http://localhost:10994/GetMunicipiosCargaJSON?value=17

在Action之前的路径中Controller消失了,所以报错404

【问题讨论】:

    标签: c# json web model-view-controller getjson


    【解决方案1】:

    问题已解决: 在提交时我有:

    return RedirectToAction("Index");
    

    现在:

    return new RedirectResult("Index");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-14
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 2015-10-05
      • 2021-12-10
      相关资源
      最近更新 更多