我是MVC的新手。当用户点击按钮时,我想将我的组合框与服务器端数据绑定。
感谢你 Hasibul
答案 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);
});
}