Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
public static List<crbt_promotion> getplinks()
        {
            List<crbt_promotion> plinks = new List<crbt_promotion>();
            using (crbt_onwebEntities dbContext = new crbt_onwebEntities())
            {
                plinks = (from z in dbContext.CRBT_Promotion select z).OrderByDescending(x=>x.id).ToList();
            }
      
            return plinks;          
        }      

Above is my method written in class file not in controller and below is my View Page :-


Razor
@{
    List<mvclogin.models.crbt_promotion> listCRBT_pro = mvclogin.service.implement.getplinks();
     
    ViewBag.Title = "CRBT Promotional Portal";
}
<div>
<table>
<tr style="background:#f4f4f4; height:20px; width:100%">
    <th align="center">ID</th>
    <th align="center">Album Name</th>
    <th align="center">Song Name</th>
    <th align="center">Link</th>
    <th align="center">Creation Date</th>    
    </tr>
    @{
    if(listCRBT_pro.Count>0)
    {
        foreach(mvclogin.Models.CRBT_Promotion promotionlist in listCRBT_pro)
        {
     <tr class="divmis">
    <td>@promotionlist.id</td>
    <td>@promotionlist.AlbumName</td>
    <td>@promotionlist.SongName</td>
    <td>@promotionlist.Link</td>
    <td>@promotionlist.CreationDate</td>
    </tr>
    }
    }
    }
</table>
</div></mvclogin.models.crbt_promotion></crbt_promotion></crbt_promotion></crbt_promotion>
Posted
Updated 7-Mar-14 12:06pm
v2

1 solution

First, implement IPagable in any viewmodel that you have in your project that you want to enhance with Pagination functionality.

SQL
namespace ar.com.juanpabloibanez.Samples.ViewModels
{
    public class SearchProducViewModel : IPageble
    {
        public SearchProducViewModel()
        {
            PagerViewModel = new PagerViewModel();
        }

        public PagerViewModel PagerViewModel { get; set; }

        public IEnumerable<Product> ListOfProducts { get; set; }
        public bool Active { get; set; }
        public string Name { get; set; }
        public int Delete { get; set; }
    }
}


Then use the @Html.Pager helper method in the view and pass to it an instance of PagerViewModel class that you can obtain from your model.

@using ar.com.juanpabloibanez.MVC.PagerHelper.Helpers
@using ar.com.juanpabloibanez.Samples.ViewModels
@model SearchProducViewModel

<table>
    <thead>
    <tr>
        <th>Name</th>
        <th>Price</th>
        <th>Active</th>
        <th>Action</th>
    </tr>
    </thead>
    <tbody>
    @foreach (var product in Model.ListOfProducts)
    {
        <tr>
            <td>@product.Name</td>
            <td>@product.Price</td>
            <td>@product.Active</td>
            <td><button name="Delete" value="@product.Id" type="submit" class="deleteButton">Delete</button></td>
        </tr>
    }
    </tbody>
</table>
@Html.Pager(Model.PagerViewModel)


Please check this link for more info : PagerHelper for ASP.NET MVC3
 
Share this answer
 
Comments
Peter Leow 8-Mar-14 1:56am    
Excellent, +5!
Sampath Lokuge 8-Mar-14 1:57am    
Thanks Peter. :)

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