Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You didn't cite what you're actual error is, but I think I see what's wrong:</p> <p>These two lines will return your an IEnumerable containing your results.</p> <pre><code>var paginatedArticles = OrderedArticles.Skip((page ?? 0) * pageSize).Take(pageSize).ToList(); return View(paginatedArticles); </code></pre> <p>However, based on your view and the helper class you posted, you're view is expecting <code>PaginatedList</code> object as its Model.</p> <p>If that's the case, I'd do the following (<strong>updated</strong>):</p> <pre><code>var paginatedArticles = new PaginatedList( OrderedArticles, page ?? 0, pageSize ); return View(paginatedArticles); </code></pre> <p>And then your view should have the proper model being returned to it.</p> <p>That said: I don't know why you aren't using a repository layer, but unless your app is only a single page it is almost always a good idea to have one in place.</p> <p><strong>Update</strong> --here's what I think the full controller logic should be:</p> <pre><code>public ActionResult Index(String query, int? page) { const int pageSize = 4; var ArticleQuery = from m in _db.ArticleSet select m; // Searching if (!string.IsNullOrEmpty(query)) { ArticleQuery = ArticleQuery.Where(m =&gt; m.headline.Contains(query)); } var OrderedArticles = ArticleQuery.OrderByDescending(m =&gt; m.posted); var paginatedArticles = new PaginatedList( OrderedArticles, page ?? 0, pageSize ); // this will now be of type paginatedList. this class handles all of the paging for you, so no need to do that ahead of time return View(paginatedArticles); } </code></pre> <p>In this case, PaginatedList is NOT a helper --its a full on class that needs to be created and passed to your model. A helper in the strict definition of the word is done much differently and probably wouldn't work in your case here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload