I'm dabbling with ASP.net MVC and slowly working through this excellent tutorial
. I've got to the point where I've created a lookup list of movie genres which is used for searching the list of movies. I now realise that it would be useful to have the same list when creating or editing a movie. I realise that it is bad practice to recreate the code each time for the routing methods. So how would I organise the code so it is placed in one location and then referenced from there wherever I need it.
public ActionResult SearchIndex(string movieGenre, string searchString)
//+++++++++START OF GENRE LIST CREATION+++++++++++++++
var GenreLst = new List<string>();
var GenreQry = from d in db.Movies
ViewBag.movieGenre = new SelectList(GenreLst);
//+++++++++END OF GENRE LIST CREATION+++++++++++++++
var movies = from m in db.Movies
movies = movies.Where(s => s.Title.Contains(searchString));
return View(movies.Where(x => x.Genre == movieGenre));
public ActionResult Create()
//++++++I'd like to create the genre list here before being passed
//to the create movie view without repeating the section of code
//from the searchIndex method above++++++++
I'm guessing that I create a public method within the same class and call it from both of the other methods.
Any help would be appreciated.