我现在坚持了一段时间并且会感激任何帮助。
当我点击分页列表中的2项时,ViewBag.SearchTerm的值为null。我的列表页面存在于部分视图(_CentraladdrcdoQuery)中,如下所示
@using SFRS.GazMatching.Web.DAL
@model IPagedList<CentraladdrcdoQuery>
@using PagedList;
@using PagedList.Mvc;
<div id="results" class="col-md-10">
<div class="row">
<div class="col-md-4">
<table class="table pull-left table-condensed">
<tr>
<td>
@Html.DisplayNameFor(model => model.First().RecordId)
</td>
</tr>
</table>
</div>
<div class="col-md-4">
<table class="table pull-left table-condensed">
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.RecordId)
</td>
</tr>
}
</table>
</div>
<br />
</div>
<div class="row">
<div class="col-md-4 clearfix">
@Html.PagedListPager(Model, page => Url.Action("Search", new { page, ViewBag.SearchTerm }), new PagedListRenderOptions
{
LinkToFirstPageFormat = "<<",
LinkToPreviousPageFormat = "prev",
LinkToNextPageFormat = "next",
LinkToLastPageFormat = ">>",
})
</div>
</div>
主要搜索视图是
@model IPagedList<CentraladdrcdoQuery>
@{
SearchFormViewModel searchFormViewModel = new SearchFormViewModel();
}
@Html.Partial("_SearchForm",searchFormViewModel)
<h2>Search Results</h2>
@Html.Partial("_CentraladdrcdoQuery", Model)
并且搜索控制器操作是
public ActionResult Search(string searchTerm, int? page)
{
var centraladdrcdoQuerylst= GetCentraladdrcdoQueryData(searchTerm,page);
ViewBag.SourceList = GetSourceList();
ViewBag.SearhTerm = searchTerm;
return View(centraladdrcdoQuerylst);
}