我刚刚为我的项目安装了Grid.mvc
包,并使用Html.Grid
方法绘制了一个基本网格:
@Html.Grid(Model).Named("FeedbackGrid").Columns(columns =>
{
columns.Add(c => c.Id).Titled("Request Number").SetWidth("10%");
columns.Add(c => c.AspNetUser.FullName).Titled("Requester").Filterable(true).SetWidth("15%");
columns.Add(c => c.RequestedDate).Titled("Date Requested").SetWidth("15%");
columns.Add(c => c.Title).Titled("Title").SetWidth("20%");
columns.Add(c => c.Description).Titled("Description")
.RenderValueAs(c => c.Description.Substring(0, (c.Description.Length > 50) ? 50: c.Description.Length)
+ ((c.Description.Length > 50) ? "..." : "")).SetWidth("40%");
}).WithPaging(10).Sortable(true)
这是我的模型:
@model IEnumerable<MyProject.Models.FeatureRequest>
我已经在屏幕上添加了一些搜索功能(例如id、姓名等)有一个搜索按钮。当单击搜索时,jquery从操作方法中提取一些新数据并将其返回给视图(与模型的类型相同)。这就是我被卡住的地方。我不知道如何使用新检索的数据重新填充网格。下面是代码。任何帮助都将不胜感激。
var onSearchClicked = function(){
var requestId = $('#RequestIdSearch').val();
var requesterId = $('#RequesterIdSearch').val();
var title = $('#TitleSearch').val();
var description = $('#DescriptionSearch').val();
$.ajax({
cache: false,
type: "POST",
url: "/Home/GetFeatureRequests",
data: { "requestId": requestId, "requesterId": requesterId, "title": title,"description": description},
success: function (rdata) {
// How to bind the grid to the retrieve rdata here?
alert('successful');
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Failed to retrieve request features!.');
}
});
}
发布于 2017-02-22 14:16:54
将您的HTML.Grid
放入Partial View
中。然后从控制器返回Partial View
,如下所示:
public PartialViewResult GetFeatureRequests(int requestId, int requesterId, string title, string description)
{
// Your code here to fill model IEnumerable<MyProject.Models.FeatureRequest>
return PartialView("_PartialViewName", model); // returns view with model
}
在ajax success function
中,执行以下操作:
$.ajax({
cache: false,
type: "POST",
url: "/Home/GetFeatureRequests",
data: { "requestId": requestId, "requesterId": requesterId, "title": title,"description": description},
success: function (rdata) {
$('#yourContainerId').html(rdata);
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Failed to retrieve request features!.');
}
});
在您的主视图中,包含如下的局部视图
<div id="yourContainerId">
@Html.Partial("_PartialViewName", Model.FeatureRequestList)
</div>
https://stackoverflow.com/questions/42382333
复制相似问题