页面列表上的模型变为空第2页单击 [英] Model becomes empty on pagedlist 2nd page click

查看:77
本文介绍了页面列表上的模型变为空第2页单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

型号:

Model:

public class Cedim
    {
        public float PEGID { get; set; }
        public float PIGID { get; set; }
        public float Type { get; set; }
    }





查看:





View:

@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:

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





我的尝试:



当我点击第二页时,模型在Controller中填充并传递给View但在View上变为空。



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.

推荐答案

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



查看此信息,您将获得详细信息。
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.


这篇关于页面列表上的模型变为空第2页单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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