ASP.NET Telerik组合框未使用新值进行更新

问题描述 投票:0回答:1

我有一个使用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控制器中的函数的新值更新combox:

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),但是combox并未加载新值。我不明白发生了什么...

c# asp.net-mvc telerik telerik-mvc telerik-combobox
1个回答
0
投票

我已经解决了。问题是我被带到了组合框中而不是组合实例中的当前项目选定值。

更改:

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

作者

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

正在工作。

© www.soinside.com 2019 - 2024. All rights reserved.