This is My View
@using(@Html.BeginForm("CrmBlogGroupType","knowledge",FormMethod.Get)){
@Html.TextBox("search")
@Html.Hidden("type", (string)ViewBag.type)
@Html.DropDownList("PageSize",
new List<SelectListItem>()
{
new SelectListItem ()
{
Text="--Select Page Size--" ,Value="10",Selected=true
},
new SelectListItem ()
{
Text="View 20 records" ,Value="20"
},
new SelectListItem ()
{
Text="View 50 records" ,Value="50"
},
new SelectListItem ()
{
Text="View 100 records" ,Value="100"
},
})
<input type="submit" value="search" id="Searchbtn" />
<br />
@Html.CheckBox("Name")<text>Author Name</text>
@Html.CheckBox("AuthorTitle")<text>Title</text>
@Html.CheckBox("Description")<text>Description</text>
}
Here is the PagedList Code
@Html.PagedListPager(Model, page => Url.Action("CrmBlogGroupType",
new {page,Name=Request.QueryString["Name"].ToLower().Contains("true"),
AuthorTitle=Request.QueryString["AuthorTitle"].ToLower().Contains("true"),
Description=Request.QueryString["Description"].ToLower().Contains("true"), search=Request.QueryString["search"],PageSize=Request.QueryString["PageSize"],type=Request.QueryStrin g["type"]}),new PagedListRenderOptions()
{
DisplayLinkToFirstPage=true,DisplayLinkToLastPage=true,DisplayPageCountAndCurrentLocation=true,Displa yItemSliceAndTotal=true
,DisplayEllipsesWhenNotShowingAllPageNumbers=true,MaximumPageNumbersToDisplay=10
})
Controller Code
public ActionResult CrmBlogGroupType(int? page, bool? Name, bool? AuthorTitle, bool?Description, string search, int? PageSize, string type)
{
if (type==null)
{
//setting the Value in the initial call
//If the SP has changed then make the type parameter as the INT
type = "A";
}
IEnumerable<Usp_getBlogSetPosts_Result> _objBlogSet = _dataLayer.GetBlogSet(type).ToList().ToPagedList(page ?? 1, PageSize ?? 10);
return View(_objBlogSet);
}
Getting an ERROR :
Object reference not set to an instance of an object.
Line 202: @if (ViewBag.Search!=null && ViewBag.Search!=string.Empty)
Line 203:{
Line 204:@Html.PagedListPager(Model, page => Url.Action("CrmBlogGroupType", new { page,
Line 205:Name=Request.QueryString["Name"].ToLower().Contains("true"),AuthorTitle=Request.QueryString["Auth orTitle"].ToLower().Contains("true"),
Line 206:Description=Request.QueryString["Description"].ToLower().Contains("true"),
I've gone through some links by which i could make up the code like this, at last got stuck here Any help on this is highly appreciated..
Use the
ViewBag
for passing the various parameters to thePagedListPager
. Calculate the values in the controller and don't have complex logic in a view. Pulling parameters fromquerystring
, when the controller has strongly typed values for those, is an unnecessary duplication of effort.and use them in the view like this:
etc
Update: 10,000 records is currently slow
From the comments below the current paging is slow. That is because the
ToList()
in the following line causes all records to be returned before any paging is applied to the LINQ query.ToPagedList
is designed to work an anIQueryable
so that when it addsSkip(n)
andTake(n)
to the query it will efficiently return just the page worth of records. Simply remove theToList()
: