简体   繁体   中英

The model item passed into the dictionary requires a model item of type 'PagedList.IPagedList

[1] i have this Error The model item passed into the dictionary is of type 'System.Collections.Generic.List but this dictionary requires a model item of type 'PagedList.IPagedList`1[OpenOrderFrame

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

and in my View i have the code as this:

@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] please help me with the code , I'm so fed up i want to pass the list of items in jo to view page.. THANKS

You are returning to View jo ( View(jo) here:

return View(jo);

which is not of type IPagedList<OpenOrderFramework.Models.Item> .

It looks like you have mistakenly passed jo variable instead of items back to View method. Changing it to passed items should fix it.

Side Note: I am not sure what you are doing as your creating jo by doing some linq on items but then later down you are again doing some operations on items and returning instead jo back. So you need to remove the code which is extra there.

You're returning jo but don't you want to return items ?

 return View(items);

Or make jo a PagedList...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM