日期:2014-05-17 浏览次数:20511 次
private MovieDBContext db = new MovieDBContext();
private UserDBContext udb = new UserDBContext();
//
// GET: /Movies/
public ActionResult SearchIndex(string movieGenre, string searchString)
{
var GenreLst = new List<string>();
var GenreQry = from d in db.Movies
orderby d.Genre
select d.Genre;
GenreLst.AddRange(GenreQry.Distinct());
ViewBag.movieGenre = new SelectList(GenreLst);
var movies = from m in db.Movies
select m;
if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
if (string.IsNullOrEmpty(movieGenre))
return View(movies);
else
{
return View(movies.Where(x => x.Genre == movieGenre));
}
}
public class MovieDBContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
}