过滤器工作正常,我正在获得正确的数据,但我无法在搜索框中保留搜索字符串。我无法找出代码中的错误
[HttpGet]
public async Task<IActionResult> GetAllLeaves(int? page, string sortOrder, string currentFilter, string employeeName, string employeeId = null, )
{
var leaves = await _employeeLeaveRepository.GetAllLeavesOfUsers();
if (!String.IsNullOrEmpty(employeeName))
{
leaves = leaves.Where(e => e.FullName.ToLower().Contains(employeeName.ToLower()));
// return View (employeeViewList.ToList());
}
else
{
employeeName = currentFilter;
}
ViewBag.CurrentFilter = employeeName;
// .............
// other code
// .............
int pageSize = 10;
int pageNumber = (page ?? 1);
return View(leaves.OrderByDescending(s => s.LeaveStatus).ToPagedList(pageNumber, pageSize));
}
视图:
<form method="get" class="mt-5" asp-controller="Leave" asp-action="GetAllLeaves">
<div class="form group col-md-6">
<label>Employee </label>
<div class="col">
<input type="hidden" id="employeeId" name="employeeId" />
<input type="text" name="employeeName" id="employeeName" />
</div>
</div>
</form>
您可以将employeeName
存储在ViewBag中:
ViewBag.EmployeeName= employeeName;
然后将其设置为输入的值:
<input type="text" name="employeeName" id="employeeName" value="@ViewBag.EmployeeName" />