im an amature arising developer in mvc 4.0. i have started to write code for a website through mvc framework but i have an issue. The pageination is not getting correctly i have seen many sites but im not able to resolve the issue can any one help me out regarding this.
CONTROLLER:
public ActionResult ProductsLanding(int? page)
{
int pagesize = 5;
int PageNumber = (page ?? 1);
SMDal objGrid = new SMDal();
DataTable dt = new DataTable();
UsersPoco user = new UsersPoco();
if (user == null)
{
Response.Redirect("Index");
}
user = (UsersPoco)Session["LoginUser"];
if (Request.QueryString["catid"] != null && Request.QueryString["catid"].ToString() != string.Empty)
{
categoryId = Convert.ToInt32(Request.QueryString["catid"]);
}
List<productitem> lstProducts = new List<productitem>();
List<productitem> lstSortedProducts = new List<productitem>();
ProductItem objprdt = new ProductItem();
lstProducts = objBal.GetAllProductDetails(user.CorgInternalId);
var query = (from s in lstProducts
where s.ProductCategoryId == categoryId
select s).ToList();
lstSortedProducts = (List<productitem>)query;
lstProducts.Add(objprdt);
if (Request.HttpMethod != "Get")
{
page = 0;
}
return View("ProductsLanding", lstProducts.ToPagedList(PageNumber, pagesize));
}
View/Home/ProductsLanding.cshtml
<div style="float:left; margin-removed100px;">
@* page @(Model.PageCount<model.pagenumber mode="hold" /> of @Model.PageCount*@
<table cellspacing="0">
<tr>
@if(Model.HasPreviousPage)
{
<td style="width:30px;">
@Html.ActionLink("First", "ProductsLanding", new { page = 1 }, new { style = "color:#ff9900; text-decoration:none;font-family: Helvetica, Arial, sans-serif; font-size:12px; font-weight:bold;" })
</td>
<td></td>
<td style="width:30px;">
@Html.ActionLink("Previous", "ProductsLanding", new { page = Model.PageNumber - 1 }, new { style = "color:#ff9900; text-decoration:none;font-family: Helvetica, Arial, sans-serif; font-size:12px; font-weight:bold;" })
</td>
<td style="width:10px;"></td>
}
@if (Model.HasNextPage)
{
<td style="width:20px;">
@Html.ActionLink("Next", "ProductsLanding", new { page = Model.PageNumber + 1 }, new { style = "color:#ff9900; text-decoration:none;font-family: Helvetica, Arial, sans-serif; font-size:12px; font-weight:bold;" })
</td>
<td style="width:10px;"></td>
<td style="width:30px;">
@Html.ActionLink("Last", "ProductsLanding", new { page = Model.PageCount }, new { style = "color:#ff9900; text-decoration:none;font-family: Helvetica, Arial, sans-serif; font-size:12px; font-weight:bold;" })
</td>
}
</tr>
</table>
</div>
My problem is the pagination is not appearing correctly... please can anyone help me out in this regard??