
1.读取20条最新留言
public ActionResult Index()
{
var mostRecentEntries = (from entry in _db.Entries
orderby entry.DateAdded descending
select entry).Take(); ViewBag.Entries = mostRecentEntries.ToList();
return View();
}
2.搜索电影
public ActionResult SearchIndex(string searchString)
{
var movies = from m in db.Movies
select m; if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
} return View(movies);
}