Paging in ASP.Net MVC

Here , you wil get simplest solution for " How to do paging in MVC ? "

Step 1: 

Download following .dll from here.

*.dll build in .net 3.5 (VS2008)


Step 2:

Add as reference to your solution.

Right Click to solution ->  Add reference -> Browse downloaded DLL -> Select it


Step 3:

 In Controller of Project ,

 Add line on top of page " using  MvcPagingByNihar  "

  public ActionResult Index(int? page)
        {

            page = page - 1;
            if (page < 0)
                page = 0;

           Ienumerable<tableName> mymaterial= /*Your query*/

            ViewData["numpages"] = mycount / 9;
            ViewData["curpage"] = page;

            return View(new PagedList<TableName>(myMaterial, page??0, pagesize,mycount));

      }


Step 4:  Index (View Page)

Current Page
    <%=Convert.ToInt32(ViewData["curpage"]) + 1 %>
    of
    <%=ViewData["numpages"] %><br />
    <br />
    <div id="paging">
        <table>
            <tr>
                <%
                    for (int i = 1; i <= Convert.ToInt32(ViewData["numpages"]); i++)
                    {
                %>
                <td style="border: 2px">
                    <%--style="background-color: Aqua; border-width: thin"--%>
                    <span><b style="color: Gray">
                        <%= Html.ActionLink(i.ToString(),"Index","ControllerName",new{page=i},null) %>
                    </b></span>
                </td>
                <%
                    }%>
            </tr>
        </table>


 Enjoy !!...

If any  problem arise with dll .Please comment here.
 

Comments

Popular posts from this blog

Add Serial no in crystal report without coding

File operations in C# (.net)

SQL – Generate decimal numbers sequence for particular number range