我如何将客户端的MVC Combobox与服务器端数据绑定

时间:2011-06-22 04:47:45

标签: combobox telerik-mvc

我是MVC的新手。当用户点击按钮时,我想将我的组合框与服务器端数据绑定。

感谢你 Hasibul

1 个答案:

答案 0 :(得分:0)

在控制器上使用以下代码:

 public List<ReceiveType> _data = new List<ReceiveType> { 
                new ReceiveType{ReceiveTypeID=1,ReceiveTypeName= "Purchase Order"},
                new ReceiveType{ReceiveTypeID=2,ReceiveTypeName= "Sales Return"},
                new ReceiveType{ReceiveTypeID=3,ReceiveTypeName= "FOC"}
            };

 public string load_cmbBoxWithServerSideDataFromClient() 
        {
          var _List = new SelectList(_data, "ReceiveTypeID", "ReceiveTypeName");
          return new JavaScriptSerializer().Serialize(_List);
        }

在视图页面上使用以下代码

@(Html.Telerik().ComboBox().Name("cmbLoadServerData"))
<input type="button" value="load" onclick="load_ServerDataFromClient()" /><br />

function load_ServerDataFromClient() {
        var cmb = $('#cmbLoadServerData').data('tComboBox');

        $.get("/Home/load_cmbBoxWithServerSideDataFromClient", function (response) {

            var selectList = $.parseJSON(response);
            cmb.dataBind(selectList, true);
        });
     }