我正在将Kendo下拉列表从现有代码转换为Kendo multiselect。
角色代码:当前为Dropdownlist(转换为Kendo multiselect)。
我没有得到正确的输出。
我有以下代码:
<div class="col-md-4 form-group"> @Html.LabelFor(model => model.RoleCode, htmlAttributes: new { }) <span style="color: Red">*</span> <select id="DDRolecode" multiple="multiple" data-placeholder="Select attendees..."> </select> </div> ... ... var url = '@Url.Action("GetRoleCode", "FlowGenerator")'; url = url + '?FlowID=' + flowid + '&RegID=' + RegId; $.ajax({ url: url, dataType: 'json', type: 'POST', success: function (result) { debugger; //$("#DDRolecode").kendoDropDownList({ // dataTextField: "Name", // dataValueField: "ID", // optionLabel: "Select", // dataSource: result //}); $("#DDRolecode").kendoMultiSelect({ dataTextField: "Name", dataValueField: "ID", dataSource: result, }); var selectedData = []; for (var i = 0; i < result.length; i++) { selectedData.push({ text: result[i].Name, value: result[i].ID }) } DDRoleCode.dataSource.data(selectedData); //DDRoleCode.setDataSource(selectedData); DDRoleCode.value(''); DDRoleCode.enable(true); }, error: function (data) { debugger; var itemRow = "<ul id='listError'><li>" + "Data Not Bind" + "</li></ul>"; FUNMessageBox(itemRow, "E", 0, 0, "", ""); // alert("error"); } });
下面是获取角色代码的控制器代码:
public JsonResult GetRoleCode(int FlowID,int RegID) { IEnumerable<GenericValues1> RoleCode = _repository.Context.Database.SqlQuery<GenericValues1>("PROC_GET_ROLECODE @DATA_FLOW_ID={0},@REG_ID={1}", FlowID, RegID).ToList().AsQueryable(); // ViewBag.Tariffs = RoleCode; return Json(RoleCode, JsonRequestBehavior.AllowGet); }
如您所见,我尝试在上面的代码中使用多选功能。但这没有用。
下面的代码为我工作:
$(document).ready(function () { debugger; $("#DDRolecode").kendoMultiSelect({ dataTextField: "Name", dataValueField: "ID", }); .... .... //go to controller and call Sp and get the result success: function (result) { debugger; var multiSelect = $('#DDRolecode').data("kendoMultiSelect"); multiSelect.value([]); $("#DDRolecode").data("kendoMultiSelect").setDataSource(new kendo.data.DataSource({ data: result })); var selectedData = []; for (var i = 0; i < result.length; i++) { selectedData.push({ Text: result[i].Name, Value: result[i].ID }) }