Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone...

in paging in web page in mvc it result a error:
The model item passed into the dictionary is of type 'PagedList.PagedList`1[SelemHomes.Models.tbl_market_news]', but this dictionary requires a model item of type 'PagedList.IPagedList`1[SelemHomes.Models.News]'.
How i can fix that and paging in the web page is run

my code in HomeController.cs:
public ActionResult News(int? page)
    tbl_katigories tbl_katigori = db.tbl_katigories.Find(6);

    ViewBag.Desc = tbl_katigori.Desc;
    ViewBag.Keywords = tbl_katigori.Keywords;
  //  ViewBag.Title1 = "Hello Mustafa";
 //   News marketnews = new News();
   // IEnumerable<tbl_market_news> news = db.tbl_market_news.OrderByDescending(s => s.Date);
 //   tbl_katigories kat = db.tbl_katigories.Find(id);

    return View(db.tbl_market_news.OrderBy(s => s.Date).ToList().ToPagedList(page ?? 1, 3));                          

and the code in News.cshtml:
@using PagedList;
@using PagedList.Mvc;
@model IPagedList<>
@foreach (var item in Model)
            @Html.DisplayFor(modelitem => item.ID)

How I can fix that, anyone help me about that, i thank so much
Mostafa Asaduzzaman 20-Jun-15 20:13pm    
there is a mixup between your two models News and tbl_market_news, the error message clearly states that. Make sure that your controller actions sends the information to the view and the view renders the actual information that it receives.

1 solution

In your view you defined the model type as IPagedList<>, but you are returning IPagedList<selemhomes.models.tbl_market_news>...
You have two options according the reality of your application...
1. Change @model IPagedList<> to @model IPagedList<selemhomes.models.tbl_market_news>
2. Change your LINQ to return IPagedList<>, something like return View( => s.Date).ToList().ToPagedList(page ?? 1, 3));
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900