0

我有一个使用 Telerik 控件的 ASP.NET MVC 应用程序。我是 Telerik 控件的新手。

在我的 asp.net 视图(.cshtml)中,我定义了 Telerik 组合框:

<div class="inline-form-field">
    <label>@Ubicaciones.lblTipoVia.ToUpper()</label>
    @(Html.Telerik().DropDownListFor(t => t.tipoViaId)                              
        .BindTo(new SelectList(@ViewBag.tiposVia, "tipoViaId", "descripcion"))
    .HtmlAttributes(new { style = "width: 190px;" })

    )
</div>

稍后在同一视图中,当满足条件时,我在下面调用 javascript 函数,以便使用来自 ASP.NET MVC 控制器中的函数的新值更新组合框:

function cargarTiposVia(){        
    var comboTiposVia = $('#tipoViaId').data('tDropDownList').value();
    var actionUrl = '@Url.Action("GetTiposVia", "Ubicaciones")?municipioId=' + $('#codigoMunicipio').val() + '&localidadId=' + $('#codigoLocalidad').val() ;
    $.ajax({
        url: actionUrl,
        async:false,
        type: "POST",
        traditional: true,
        success: function (data) {
            if (data)
            {       
                comboTiposVia.dataBind(data);
            }
        }
    });
}

在 ASP.NET MVC 控制器中的 GetTiposVia 函数下方:

    public JsonResult GetTiposVia(string municipioId, string localidadId)
    {
        CommonManager commonManager = new CommonManager(currentUserSociedadId);
        List<My.DTOs.TipoViaDTO> tiposVia = commonManager.getTiposViaByMunicipio(municipioId);
        //ViewBag.tiposVia = tiposVia;
        return Json(new SelectList(tiposVia, "tipoViaId", "descripcion"), JsonRequestBehavior.AllowGet);
    }

Ajax 结果是成功的(我已经通过发出警报进行了检查),因此执行了 comboTiposVia.dataBind(data) 但未加载新值的组合框。我不明白发生了什么……

4

1 回答 1

0

我已经解决了。问题是我在组合框中获取了当前项目选择的值,而不是组合框实例。

改变:

var comboTiposVia = $('#tipoViaId').data('tDropDownList').value();

经过

var comboTiposVia = $('#tipoViaId').data('tDropDownList');

正在工作中。

于 2020-01-18T12:31:53.447 回答