【发布时间】:2021-07-24 04:33:33
【问题描述】:
我有一个剑道 kendoDropDownList。我试图通过调用 Ajax 来填充下拉值。不幸的是,每次我单击下拉列表时,它都会调用 Action 并返回值,但下拉列表不显示列表。我用一个简单的字典测试了几次,它适用于测试数据(显示在代码中),但是当我用真实数据填充相同的数据时,它没有显示下拉值。如果我做错了什么,你能看看吗?
行动:
public ActionResult SubmitterActionTypes(int id)
{
var types = ServiceProvider.SupplementalDataService.SubmitterActionTypes()
.OrderBy(x => x.Name);
Dictionary<int, string> typesDic = new Dictionary<int, string>();
// Following Test code works fine and drop down populates with values...
/*typesDic.Add(1, "Item 1");
typesDic.Add(2, "Item 2");
typesDic.Add(3, "Item 3");
typesDic.Add(4, "Item 4");*/
// Following code does not work and dropdown does not show any result
foreach(var type in types)
{
if (type.Name!=null && type.Name != "None")
{
typesDic.Add(Convert.ToInt32(type.SubmitterActionRequiredTypeID), type.Name.ToString());
}
}
return PartialView("JsonResult", typesDic.ToList());
}
阿贾克斯:
var submitterActionRequired = $("#submitterActionRequired").kendoDropDownList({
optionLabel: "Select User Assignee...",
dataTextField: "Value",
dataValueField: "Key",
height: 310,
Width: "900px",
dataSource: {
transport: {
read: function (options) {
$.ajax({
url: "/Submission/SubmitterActionTypes",
dataType: "JSON",
data: {
id: EntityOrganizationID
},
success: function (result) {
// notify the data source that the request succeeded
options.success(result);
},
error: function (result) {
// notify the data source that the request failed
options.error(result);
}
});
}
}
}
}).data("kendoDropDownList");
【问题讨论】:
标签: c# ajax asp.net-mvc action kendo-dropdown