asp.net - 搜索后的非因素分页问题
问题描述
我在我的项目中使用 NonFactors mvcgrid6 ( https://mvc6-grid.azurewebsites.net/ ),并且在搜索后分页中断。例如,在进行搜索后选择第 2 页时,将返回整个数据集,而不仅仅是搜索的数据。
寻找一种在使用分页时持久保存搜索到的数据的方法。这可能与这个插件有关吗?
控制器
public IActionResult Index(IndexResidentVM searchValues)
{
var indexVm = new IndexResidentVM()
{
SearchItems = _residentService.GetAllResidents(searchValues).AsQueryable(),
Groups = _groupService.GetGroups(),
Users = _userService.GetUsers()
};
return View(indexVm);
}
指数
@using CommunityContact.Core.Enums
@using NonFactors.Mvc.Grid
@model CommunityContact.Core.ViewModels.Resident.IndexResidentVM
@{
ViewData["Title"] = "Residents";
}
<h3>Allocated Residents</h3>
<form asp-action="Index" id="indexSearchForm">
<div class="form-row">
<div class="form-group col-md-3" style="margin-top: 15px;">
<label class="col-md-3">Group: </label>
<select id="indexGroupDdl" asp-for="Group" asp-items="@Model.Groups.Select(p => new SelectListItem()
{
Value = p.Name,
Text = p.Name
})" class="form-control-sm col-md-8">
<option selected="selected" value="">Please select </option>
</select>
</div>
<div class="form-group col-md-4" style="margin-top: 15px;">
<label class="col-md-4">RAG Status:</label>
<select id="indexRagStatusDdl" asp-for="RagStatus" asp-items="Html.GetEnumSelectList<Enums.RagStatus>()" class="form-control-sm col-md-6">
<option selected="selected" value="">Please select </option>
</select>
</div>
<div class="form-group col-md-4" style="margin-top: 15px;">
<label class="col-md-4">Allocated to: </label>
<select id="indexAllocatedToDdl" asp-for="User" asp-items="@Model.Users.Select(p => new SelectListItem()
{
Value = p.Name,
Text = p.Name
})" class="form-control-sm col-md-6">
<option selected="selected" value="">Please select </option>
</select>
</div>
<div class="col-md-1" style="margin-top: 15px;">
<button id="clearSearch" class="btn-sm btn-primary clear-search" title="Clear Search"><span class="fa fa-times"></span></button>
</div>
</div>
</form>
<hr />
@(Html.Grid(Model.SearchItems)
.Build(columns =>
{
columns.Add(model => model.Id).Css("hidden-column");
columns.Add(model => model.ResidentId).Titled("Resident ID");
columns.Add(model => model.Forename1).Titled("Forename");
columns.Add(model => model.Surname).Titled("Surname");
columns.Add(model => model.Group).Titled("Group");
columns.Add(model => model.CallBackDue.HasValue ? model.CallBackDue.Value.ToShortDateString() : string.Empty).Titled("Call Back Due");
columns.Add(model => model.RagStatus).Titled("RAG Status");
columns.Add(model => model.AllocatedTo).Titled("Allocated to");
columns.Add(model => Html.ActionLink(" ", "Edit", "Resident", new { id = model.Id }, new { @class = "fa fa-edit", title = "Edit" })).Css("archive-column-width");
columns.Add(model => Html.ActionLink(" ", " ", new {}, new {@class="fa fa-archive", href ="#", onclick="return archivePrompt('"+ model.Id +"')", title ="Archive"})).Css("archive-column-width");
})
.Pageable()
.RowAttributed(model => new {@class = model.RagStatus == Enums.RagStatus.Red.ToString() ? "rag-status-red" : model.RagStatus == Enums.RagStatus.Amber.ToString() ? "rag-status-amber" : model.RagStatus == Enums.RagStatus.Green.ToString() ? "rag-status-green" : null }))
@*@Html.AjaxGrid(Url.Action("Index"))*@
@section Scripts
{
<script>
// MvcGrid
[].forEach.call(document.getElementsByClassName('mvc-grid'), function (element) {
new MvcGrid(element);
});
</script>
}
查看模型
public class IndexResidentVM
{
public int Id { get; set; }
public string ResidentId { get; set; }
public string Forename1 { get; set; }
public string Surname { get; set; }
public string Group { get; set; }
public string User { get; set; }
public Enums.Enums.RagStatus RagStatus { get; set; }
public IQueryable<ResidentSearchItemVM> SearchItems { get; set; }
public IEnumerable<EditUserVM> Users { get; set; }
public IEnumerable<GroupVM> Groups { get; set; }
}
解决方案
这是通过对控制器的调用一个 GET 请求而不是 POST 来解决的。将以下内容添加到我的表单标签中为我修复了它 -
method="GET"
推荐阅读
- python - 为什么 pandas read_excel 不能正确读取 xls 文件?
- python - 如何创建一个函数来删除 Python 中的特殊字符以进行特征工程?
- javascript - 如何让我的 JavaScript 回答与第三个响应?
- r - 使用 rbindlist() 将循环中的结果附加到 data.table
- wicket - Wicket 9 和 Tomcat 10 无法投射 jakarta.servlet.Filter
- php - 如何解决带有参数 404 错误的 wordpress 重定向?
- javascript - 如何从 XMLHttpRequest 返回结果?
- javascript - 如何在 Web API 调用中设置闭包?
- ios - GoogleDataTransport][I-GDTCOR001006] 问题?
- postgresql - 无法打开驱动程序的连接:org.eclipse.birt.report.data.oda.jdbc。使用数据库 postgres