我无法刷新我的 WebGrid。我想使用存储过程基于字符串过滤器进行搜索。在控制器中,我的列表会针对给定的字符串过滤器进行更新。但我无法通过 ajax 将此数据传递给 UI。如果有人可以帮助我吗?
索引.cshtml:
<script type="text/javascript">
function search(searchby) {
$.ajax({
type: "post",
url: "/Home/searchCPW",
data: { search: searchby, action: 'Client' },
datatype: "json",
traditional: true,
done: function (data) {
alert('Done');
},
success: function (data) {
// debugger
if (data == "No Record Found") {
alert('No Record Found');
}
else {
$("#gridContent").html(response);
$('#search').val(searchby);
}
}
});
}
</script>
@Html.TextBox("txtbx1", "", new { onkeyup = "search($(this).val());", id = "#search" })
@{
Html.RenderPartial("_SearchCPW",Model);
}
控制器功能:
public ActionResult searchCPW(string search,string action)
{
List<p_search_ccpw_CPW> lstSearchModel = new List<p_search_ccpw_CPW>();
List<p_search_ccpw_CPW> lstSearchMasters = entities.p_search_ccpw_CPW("", search, action).ToList();
lstSearchMasters.ForEach(x =>
{
p_search_ccpw_CPW stuModel = new p_search_ccpw_CPW();
stuModel.Name = x.Name;
stuModel.ID = x.ID;
lstSearchModel.Add(stuModel);
});
if (lstSearchModel.Count > 0)
{
return View("_SearchCPW", lstSearchModel);
}
else
{
return Json("No Record Found");
}
}
部分观点:_SearchCPW
@model IEnumerable<TestingGrid.p_search_ccpw_CPW>
@{
ViewBag.Title = "_SearchCPW";
}
@{
var grid = new WebGrid(source: Model, canPage: true, rowsPerPage: 5,
selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.All);
}
@grid.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("ID", " ID"),
grid.Column("Name", "Name")))