Click here to Skip to main content
15,913,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
public ActionResult ProductsLanding(int? page)
{
    int pagesize = 5;
    int PageNumber = (page ?? 1);


    //DataTable dtGrid = new DataTable();
    //Grid objGrid = new Grid();
    //dtGrid = objGrid.GetGridData();

    //List<grid> Gridd = new List<grid>();

    //foreach (DataRow dr in dtGrid.Rows)
    //{
    //    Grid class1 = new Grid();
    //    class1.EmpID = Convert.ToInt32(dr["EmpID"]);
    //    class1.EmpName = dr["EmpName"].ToString();
    //    class1.Designation = dr["Designation"].ToString();
    //   // class1.ImagePath = dr["ImagePath"].ToString();

    //    Gridd.Add(class1);
    //}


    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
HTML
<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??
Posted
v2
Comments
Jameel VM 13-May-13 7:24am    
appearing means?what is the actual problem?

1 solution

You should read my next article: MVC Basic Site: Step 4 – jqGrid Integration in MVC 4.0 using AJAX, JSON, jQuery, LINQ, and Serialization[^]

There is also source code provided.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900