根据搜索表单帖子更新kendo网格
-
20-12-2019 - |
题
我一直在做很多搜索,但没有找到明确的答案。我有一个设置的文本框,以及提交按钮和kendo ui网格。我想将数据发布到网格的数据源,以便它将根据标准返回结果。我没有使用MVC包装。
编辑: 我越来越近,但在单击提交时,我似乎无法获取数据源即可发送帖子数据。我已经调试和在我的$(“#fmsearch”)。提交它正在击中jQuery插件,我确认它正常将表单数据转换为JSON,但它似乎它似乎没有发送更新的信息到服务器,以便操作可以读取它。
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()); ;
}
.
行动未设置为立即检索不同的数据,我只需要知道如何将表单连接到网格。
解决方案
发现了问题。我有这个:
dsGalleryItem.read({ data: $("#fmSearch").serializeFormToJSON() });
.
需要如下:
dsGalleryItem.read($("#fmSearch").serializeFormToJSON());
. 不隶属于 StackOverflow