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

in paging in web page in asp.net 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:
C#
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:
HTML
@using PagedList;
@using PagedList.Mvc;
@model IPagedList<selemhomes.models.news>
.....
.....
.....
<table>
@foreach (var item in Model)
{                 
    <tr>
        <td>
            @Html.DisplayFor(modelitem => item.ID)
        </td>
    </tr>          
}
</table>

How I can fix that, anyone help me about that, i thank so much
Posted
v2
Comments
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<selemhomes.models.news>, but you are returning IPagedList<selemhomes.models.tbl_market_news>...
You have two options according the reality of your application...
1. Change @model IPagedList<selemhomes.models.news> to @model IPagedList<selemhomes.models.tbl_market_news>
2. Change your LINQ to return IPagedList<selemhomes.models.news>, something like return View(db.news.OrderBy(s => 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