【发布时间】:2016-10-16 09:24:32
【问题描述】:
您好,我正在使用 Kendo MVC Grid in cell 模式,我正在尝试构建级联下拉列表,我正在尝试根据 Category 下拉列表填充 SubCategory 下拉列表。除了我得到JSON 作为undefined 返回的结果而不是实际值之外,我一切工作正常,
这是代码
@(Html.Kendo().Grid<WebApplication6.Models.SubSubCategory>()
.Name("grid")
.Events(events => events.Change("Grid_OnRowSelect"))
.Columns(columns =>
{
columns.ForeignKey(c => c.CategoryID, (System.Collections.IEnumerable)ViewData["Category"],"CategoryID","CategoryName").Title("Category");
columns.ForeignKey(c => c.SubCategoryID (System.Collections.IEnumerable)ViewData["SubCategory"], "SubCategoryID", "SubCategoryName").Title("Sub-Category");
这是ajax 部分:-
<script>
Grid_OnRowSelect = function (e) {
var CatID = (this.dataItem(this.select()).CategoryID);
$.ajax({
//url: "SubSubCategories/SearchSubCategory",
url:'@Url.Action("SearchSubCategory", "SubSubCategories")',
type: "GET",
data: { CategoryID: CatID },
dataType: "json",
success: function (retData) {
if (JSON.stringify(retData) != "[]") {
var ddl = $('#SubCategoryID').data("kendoDropDownList");
ddl.setDataSource(retData);
ddl.refresh();
}else {
alert("No");
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
}
});
<script>
这里是简单的控制器(SubSubCategories):-
public JsonResult SearchSubCategory(int CategoryID)
{
var x = ((db.SubCategories.Select(p =>
new { CategoryID = p.CategoryID, SubCategoryID = p.SubCatgeoryID, SubCategoryName = p.SubCategoryName }))
.Where(p => p.CategoryID == CategoryID));
return Json(x, JsonRequestBehavior.AllowGet);
}
提前致谢:)
【问题讨论】:
标签: jquery json asp.net-mvc kendo-asp.net-mvc kendo-dropdown