关于MVC 4.0中的分页问题的问题..请帮帮我... [英] Issue regarding the pagination problem in MVC 4.0.. please do help me out...

查看:56
本文介绍了关于MVC 4.0中的分页问题的问题..请帮帮我...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是mvc 4.0中一个不成熟的开发者。我已经开始通过mvc框架为网站编写代码,但我有一个问题。分页没有正确我已经看到很多网站,但我无法解决问题可以任何人帮助我这个。



CONTROLLER:

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);


    //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));
}





查看/主页/ ProductsLanding.cshtml



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??

推荐答案

你应该阅读我的下一篇文章:MVC Basic Site:第4步 - 使用AJAX在MVC 4.0中进行jqGrid集成, JSON,jQuery,LINQ和序列化 [ ^ ]



还提供了源代码。
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.


这篇关于关于MVC 4.0中的分页问题的问题..请帮帮我...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆