C# 传递到字典的模型项需要“PagedList.IPagedList”类型的模型项
[1] 我有此错误传递到字典中的模型项的类型为“System.Collections.Generic.List”,但此字典 需要类型为“PagedList.IPagedList`1[OpenOrderFrame]的模型项C# 传递到字典的模型项需要“PagedList.IPagedList”类型的模型项,c#,model-view-controller,C#,Model View Controller,[1] 我有此错误传递到字典中的模型项的类型为“System.Collections.Generic.List”,但此字典 需要类型为“PagedList.IPagedList`1[OpenOrderFrame]的模型项 i have my controller as this : public class ItemsController : Controller { private ApplicationDbContext db = new Appl
i have my controller as this :
public class ItemsController : Controller
{
private ApplicationDbContext db = new ApplicationDbContext();
// GET: Items
public ActionResult Index(string sortOrder, string currentFilter, string searchString, int? page)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "Name";
ViewBag.PriceSortParm = sortOrder == "Name" ? "Loc_desc" : "Location";
IEnumerable<Item> items = db.Items;
var jo = (from a in items.GroupBy(x => new { x.Catagorie, x.ItemName })
.Select(g => new
{
Category = g.Key.Catagorie,
ItemName = g.Key.ItemName,
Quantity = g.Sum(s => s.ItemQty),
Location = g.First().Location
})
select a);
if (!string.IsNullOrWhiteSpace(searchString))
{
items = items.Where(s => s.ItemName.ToUpper().Contains(searchString.ToUpper())
|| s.Catagorie.Name.ToUpper().Contains(searchString.ToUpper())||
s.Location.Name.ToUpper().Contains(searchString.ToUpper())).ToList().ToPagedList(page ??1, 20);
//}
}
else
{
items = items.ToList().ToPagedList(page ?? 1, 10);
}
return View(jo);
在我看来,我的代码如下:
@model PagedList.IPagedList<OpenOrderFramework.Models.Item>
@using PagedList.Mvc;
@using PagedList;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
@{
ViewBag.Title = "Food";
}
[2] 请帮我写代码,我受够了
我想将jo中的项目列表传递到查看页面。谢谢你正在返回jo,但你不想返回项目吗
或者让jo成为页面列表…您将返回此处查看jo Viewjo: 不是IPagedList类型的 看起来您错误地将jo变量而不是items传递回了View方法。将其更改为passed items应该可以解决此问题
旁注:我不确定在创建jo时,您是如何通过对项目执行linq操作的,但后来您又对项目执行了一些操作,并将jo返回。因此,您需要删除额外的代码。我想返回VarJot中的项目列表。如果您必须将jo设置为PagedList,您可以帮助我吗pleasereturn Viewjo.ToList.ToPagedListpage??1, 10;它抱怨:额外的信息:方法“第一”只能用作最终的查询操作。
return View(items);
return View(jo);