【发布时间】:2020-01-08 04:18:22
【问题描述】:
我正在将现有代码中的 Kendo 下拉列表转换为 Kendo 多选。
角色代码:当前下拉列表(转换为 Kendo 多选)。
我没有得到正确的输出。
我有以下代码:
<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);
}
如您所见,我尝试在上述代码中使用多选功能。但它没有用。
【问题讨论】:
-
哪一部分不是特别有效?如数据源未绑定?您选择的值是否未预设?该代码有助于尝试和跟踪问题,但您没有说明具体问题是什么。
-
@DavidShorthose ibb.co/Ln6zQ4w 请检查链接。这就是我得到的。
-
但是你又没有说/显示实际问题是什么(你只能从图像中得到这么多)。我可以看到多选在那里,但看起来它处于禁用状态,这是问题吗?
-
@DavidShorthose 我认为这是一个用户界面问题。我正在得到结果。但正如你所看到的多选结构,这对我来说是个问题。
-
@DavidShorthose 我的多选方法是否正确?因为我第一次尝试剑道..
标签: c# ajax model-view-controller kendo-ui