我一直在做很多搜索,但还没有找到明确的答案。我有一个设置文本框和一个提交按钮和一个 Kendo UI 网格。我想将数据发布到网格的数据源,以便它将根据条件返回结果。我没有使用 MVC 包装器。
编辑:我已经接近了,但是当我单击提交时,我似乎无法让数据源发送帖子数据。我已经调试并在我的 $("#fmSearch").submit 中点击了 jquery 插件,并且我已经确认它正在将表单数据正确转换为 JSON,但似乎它没有发送更新的信息到服务器,以便 Action 可以读取它。
Javascript
var dsGalleryItem = new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Content("~/Intranet/GalleryItem/SearchGalleryItems")',
type: "POST",
data: $("#fmSearch").serializeFormToJSON(),
cache: false
}
},
schema: {
model: {
id: "galleryItemID",
fields: {
galleryItemID: {
nullable: true
},
imageName: {},
collectionName: {},
categoryName: {},
lastUpdatedOn: { type: "date" }
}
}
}
});
var gvResults = $("#gvResults").kendoGrid({
autoBind:false,
columns: [{
field: "imageName",
title: "Item Name",
template: "<a href='@Url.Content("~/Intranet/GalleryItem/Details/")#=galleryItemID#'> #=imageName#</a>"
}, {
field: "collectionName",
title: "Collection"
}, {
field: "categoryName",
title: "Category"
}, {
field: "lastUpdatedOn",
title: "Last Updated",
format: "{0:M/d/yyyy}"
}
],
selectable: "row",
change: onRowSelect,
dataSource: dsGalleryItem
});
$("#fmSearch").submit(
function (event) {
event.preventDefault();
dsGalleryItem.read({ data: $("#fmSearch").serializeFormToJSON() });
});
MVC 动作
[HttpPost]
public JsonResult SearchGalleryItems(string keyword, int? category, int? collection, DateTime? startDate, DateTime? endDate)
{
var galleryItemList = (from g in db.GalleryItems
//where g.imageName.Contains(keyword)
select new GalleryItemViewModel
{
galleryItemID = g.galleryItemID,
imageName = g.imageName,
collectionName = g.collection.collectionName,
categoryName = g.category.categoryName,
lastUpdatedOn = g.lastUpdatedOn
});
var galleryItemCount = Json(galleryItemList.ToList());
return Json(galleryItemList.ToList()); ;
}
现在没有设置该操作来检索不同的数据,我只需要知道如何将表单连接到网格。