传值: <td style="width:10%"> <a href=""> @item.PostType.TypeName </a></td>
分页:<div>
@(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
/ @Model.PageCount @if (Model.HasPreviousPage) { @Html.ActionLink("<<", "GetPostTypeInfoByAea", new { page = 1, currentFilter = ViewBag.CurrentFilter }) @Html.Raw(" "); @Html.ActionLink("< 上一页", "GetPostTypeInfoByAea", new { page = Model.PageNumber - 1, currentFilter = ViewBag.CurrentFilter })}
else { @:<< @Html.Raw(" "); @:< 上一页 } @if (Model.HasNextPage) { @Html.ActionLink("下一页 >", "GetPostTypeInfoByAea", new { page = Model.PageNumber + 1, currentFilter = ViewBag.CurrentFilter }) @Html.Raw(" "); @Html.ActionLink(">>", "GetPostTypeInfoByAea", new { page = Model.PageCount, currentFilter = ViewBag.CurrentFilter }) } else { @:下一页 > @Html.Raw(" ") @:>> } </div>Controller:部分:
[ValidateInput(false)]
public ViewResult GetPostTypeInfoByAea (string currentFilter, string searchString, int? page) {if (Request.QueryString["areaid"] != null)
{ var areaid = Guid.Parse(Request.QueryString["areaid"]); var postTypeID = Guid.Parse(Request.QueryString["postTypeid"]); Session["areaid"] = areaid; Session["postTypeid"] = postTypeID;if (Request.HttpMethod == "GET") { searchString = currentFilter; } else { page = 1; } ViewBag.CurrentFilter = searchString; var TN_Post = db.TN_Post.Where(c => c.TN_Community.Areaid == areaid && c.PostTypeID==postTypeID).OrderByDescending(em => em.Views).ToList(); if (!string.IsNullOrEmpty(searchString)) { TN_Post = TN_Post.Where(e => e.PostTitle.Contains(searchString)).ToList(); } int pageSize = 10; int pageIndex = (page ?? 1) - 1; return View(TN_Post.ToPagedList(pageIndex, pageSize));
}
else { var id =Guid .Parse ( Session["areaid"].ToString()); var tid =Guid .Parse ( Session["postTypeid"].ToString()); if (Request.HttpMethod == "GET") { searchString = currentFilter; } else { page = 1; } ViewBag.CurrentFilter = searchString; var TN_Post = db.TN_Post.Where(c => c.TN_Community.Areaid == id && c.PostTypeID == tid).OrderByDescending(em => em.Views).ToList(); if (!string.IsNullOrEmpty(searchString)) { TN_Post = TN_Post.Where(e => e.PostTitle.Contains(searchString)).ToList(); } int pageSize = 10; int pageIndex = (page ?? 1) - 1; return View(TN_Post.ToPagedList(pageIndex, pageSize));}
要点用Session为载体
}