如何使用ajax动态绑定kendodropdownlist

时间:2014-10-16 05:57:44

标签: jquery kendo-asp.net-mvc

我想使用ajax动态绑定一个kendo下拉列表。任何人都可以提出一些想法,我该怎么做?

     <div id="divLocation1"></div>

我想在div“divLocation1”中输入下拉列表。

1 个答案:

答案 0 :(得分:0)

请尝试以下代码,这可能会对您有所帮助: -

  jQuery.ajax({
    type: 'GET',
    contentType: 'application/json; charset=utf-8',
    data: { param: params },
    dataType: 'json',
    async: false,
    beforeSend: function () {

    },
    url: $_YourUrl,
    success: function (result) {
        var dataLocation1 = [];          
        var _optionLabel = "Please Select";
        var source = $('<div>' + _dataHtml + '</div>');
        for (var i = 0; i < result.length; i++) {
            dataLocation1.push({ text: result[i].Text, value: result[i].Value });
        }

      $("#divLocation1").html('<select id="ddlLocation1" class="span12"></select>');
        $("#divLocation1").find("#ddlLocation1").kendoDropDownList({
            dataTextField: "text",
            dataValueField: "value",
            dataSource: dataLocation1,
            optionLabel: _optionLabel,
            autoClose: false
        });
    },

       error: function () {
     alert("Error :");
      }
  });