Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Model:
C#
public class Cedim
    {
        public float PEGID { get; set; }
        public float PIGID { get; set; }
        public float Type { get; set; }
    }


View:

HTML
@model PagedList.IPagedList<AvibuyerExcelUpload.Models.Cegedim>
@using PagedList.Mvc;

<link href="~/Content/PagedList.css" rel="stylesheet" />
<h2>Upload File</h2>

@using (Html.BeginForm("Index", "Upload", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()

    <div class="form-group">
        <input type="file" id="dataFile" name="upload" />
    </div>

    <div class="form-group">
        <input type="submit" name="Command" value="Upload Cegedim" class="btn btn-default" />
    </div>

    if (Model != null)
    {
        <table>
            <thead>
                <tr>
                    <th>PIGID</th> &nbsp;&nbsp;
                    <th>Type</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                      <td>@Html.DisplayFor(x => item.PIGID)</td>
                        <td>@Html.DisplayFor(x => item.Type)</td>
                        
                    </tr>
                }
            </tbody>
        </table>    
    }



if (Model.PageCount > 1)
{
    <div class="pager">
        @Html.PagedListPager(Model, page => Url.Action("Index", new { page,currentFilter=ViewBag.CurrentFilter, sortOrder = ViewBag.CurrentFilter}))
        Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
    </div>
}

}


Controller:

C#
public ActionResult Index(int page=1)
       {
           if (Session["Final"] == null)
           {

               List<Cegedim> listCegedim = new List<Cegedim>();
               listCegedim = new List<Models.Cegedim>();

               return View(listCegedim.ToPagedList(1,50));
           }
           else
           {

               DataTable dtCegedim = (DataTable)Session["Final"];

               int SkipRows = (page-1) * 50;

               DataTable newDtCegedim = new DataTable();
               newDtCegedim = dtCegedim.AsEnumerable().Skip(SkipRows).Take(50).CopyToDataTable();

               List<Cegedim> myList = new List<Cegedim>();

               myList = (from rw in newDtCegedim.AsEnumerable()
                         select new Cegedim()
                         {
                             PIGID = Convert.ToInt32(rw["PIGID"]),
                             Type = Convert.ToInt32(rw["Type"])
                         }).ToList();



               return View(myList.ToPagedList(page,50));
           }
       }


What I have tried:

When i click 2nd Page , the model is filled in Controller and passed to View but it becomes empty on View.
Posted
Updated 8-Sep-16 3:03am

1 solution

http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application

Check this you will get detailed information.
 
Share this answer
 
Comments
Abrar Kazi 8-Sep-16 9:47am    
I already checked that and did exactly the same still the problem exist. I dont know where i am going wrong

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