Permalink
Browse files

Step 7

  • Loading branch information...
1 parent 3e40257 commit 99c0d48ad95087301a354ccfc63dc177a3fd947e @AlexManduley committed Mar 19, 2013
Showing with 17 additions and 10 deletions.
  1. +15 −9 Controllers/MoviesController.cs
  2. +2 −1 Views/Movies/SearchIndex.cshtml
@@ -114,9 +114,16 @@ public ActionResult DeleteConfirmed(int id)
//
// Search Action
- public ActionResult SearchIndex(string searchString)
+ public ActionResult SearchIndex(string movieGenre, string searchString)
{
- //string searchString = id;
+ var GenreList = new List<string>();
+
+ var GenreQry = from d in db.Movies
+ orderby d.Genre
+ select d.Genre;
+ GenreList.AddRange(GenreQry.Distinct());
+ ViewBag.movieGenre = new SelectList(GenreList);
+
var movies = from m in db.Movies
select m;
@@ -125,14 +132,13 @@ public ActionResult SearchIndex(string searchString)
movies = movies.Where(s => s.Title.Contains(searchString));
}
- return View(movies);
-
- }
+ if (string.IsNullOrEmpty(movieGenre))
+ return View(movies);
+ else
+ {
+ return View(movies.Where(x => x.Genre == movieGenre));
+ }
- [HttpPost]
- public string SearchIndex(FormCollection fc, string searchString)
- {
- return "<h3> From [HttpPost]SearchIndex: " + searchString + "</h3>";
}
protected override void Dispose(bool disposing)
@@ -10,7 +10,8 @@
@Html.ActionLink("Create New", "Create")
@using (Html.BeginForm("SearchIndex","Movies",FormMethod.Get)){
- <p> Title: @Html.TextBox("SearchString")
+ <p> Genre: @Html.DropDownList("movieGenre", "All")
+ Title: @Html.TextBox("SearchString")
<input type="submit" value="Filter" /></p>
}
</p>

0 comments on commit 99c0d48

Please sign in to comment.