ASP.NET MVC Query Help
Posted
by
Cameron
on Stack Overflow
See other posts from Stack Overflow
or by Cameron
Published on 2011-01-05T16:25:42Z
Indexed on
2011/01/05
16:53 UTC
Read the original article
Hit count: 165
I have the following Index method on my app that shows a bunch of articles:
public ActionResult Index(String query)
{
var ArticleQuery = from m in _db.ArticleSet select m;
if (!string.IsNullOrEmpty(query))
{
ArticleQuery = ArticleQuery.Where(m => m.headline.Contains(query));
}
//ArticleQuery = ArticleQuery.OrderBy(m.posted descending);
return View(ArticleQuery.ToList());
}
It also doubles as a search mechanism by grabbing a query string if it exists.
Problem 1.) The OrderBy does not work, what do I need to change it to get it to show the results by posted date in descending order.
Problem 2.) I am going to adding a VERY SIMPLE pagination, and therefore only want to show 4 results per page. How would I be best going about this? Thanks
EDIT: In addition to problem 2, I'm looking for a simple Helper class solution to implement said pagination into my current code. This ones looks very good (http://weblogs.asp.net/andrewrea/archive/2008/07/01/asp-net-mvc-quot-pager-quot-html-helper.aspx), but how would I implement it into my application. Thanks.
© Stack Overflow or respective owner