我有一个“索引剃刀视图”(MVC5 C#),该视图仅显示名为ICS_Supplies的表中的数据列表。很好,除非有许多行数据,因此填充视图可能需要很长时间。因此,需要分页。我来自带有VB.net的旧asp.net表单,其中分页非常简单。 MVC5和C#仍然很新。 。而且我无法正常工作。
我在这里。我的模特:
namespace ICS20web.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
using PagedList;
public partial class ICS_Supplies
{
[Key]
public int Supplies_ID { get; set; }
[StringLength(25)]
public string Old_ItemID { get; set; }
[StringLength(80)]
public string ItemDescription { get; set; }
public int? OnHand { get; set; }
public int? ReorderLevel { get; set; }
public int? ReorderAmt { get; set; }
[StringLength(10)]
public string UnitMeasure { get; set; }
[StringLength(30)]
public string SupplyLocation { get; set; }
[StringLength(1)]
public string InvType { get; set; }
[StringLength(1)]
public string Discontinued { get; set; }
}
}
这是我的索引控制者
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using ICS20web.Models;
using PagedList;
namespace ICS20web.Controllers
{
public class SuppliesController : Controller
{
private ICS_Internal_Transactions db = new ICS_Internal_Transactions();
// GET: Supplies
public ActionResult Index()
{
var supplies = db.ICS_Supplies.OrderByDescending(g => g.Supplies_ID).ToList();
var model = new PagedList<ICS_Supplies>(supplies, 1, 10);
return View(model);
}
这是我的查看代码
@model PagedList.IPagedList<ICS20web.Models.ICS_Supplies>
@using PagedList.Mvc;
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Old_ItemID)
</th>
<th>
@Html.DisplayNameFor(model => model.ItemDescription)
</th>
<th>
@Html.DisplayNameFor(model => model.OnHand)
</th>
<th>
@Html.DisplayNameFor(model => model.ReorderLevel)
</th>
<th>
@Html.DisplayNameFor(model => model.ReorderAmt)
</th>
<th>
@Html.DisplayNameFor(model => model.UnitMeasure)
</th>
<th>
@Html.DisplayNameFor(model => model.SupplyLocation)
</th>
<th>
@Html.DisplayNameFor(model => model.InvType)
</th>
<th>
@Html.DisplayNameFor(model => model.Discontinued)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Old_ItemID)
</td>
<td>
@Html.DisplayFor(modelItem => item.ItemDescription)
</td>
<td>
@Html.DisplayFor(modelItem => item.OnHand)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReorderLevel)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReorderAmt)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitMeasure)
</td>
<td>
@Html.DisplayFor(modelItem => item.SupplyLocation)
</td>
<td>
@Html.DisplayFor(modelItem => item.InvType)
</td>
<td>
@Html.DisplayFor(modelItem => item.Discontinued)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Supplies_ID }) |
@Html.ActionLink("Details", "Details", new { id=item.Supplies_ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Supplies_ID })
</td>
</tr>
}
</table>
@Html.PagedListPager(Model, page => Url.Action("Index", new { page, pagesize = 5 }))
我已经按照指示安装了PagedList.MVC Nuget并在View Web.Config文件中添加了适当的引用。
页面尝试加载时,我当前收到以下错误消息:
编译器错误消息:CS1061:'IPagedList'不包含'Old_ItemID'的定义,并且找不到扩展方法'Old_ItemID'接受类型为'IPagedList'的第一个参数(是否缺少using指令或程序集参考?)
我做的第一件事是从视图中删除了对象“ Old_ItemID”,但是下一个对象生成了相同的错误。
我正在尝试解决该错误。似乎在告诉我IPagedLIST中没有“ Old_ItemID”的定义,但是当我查看模型ICS_Supplies时,定义就在那里。我在控制器中设置了错误吗?我不知道下一步去哪里。