Just working through a tutorial on asp.net/mvc for the music store application.
Ref: http://www.asp.net/mvc/tutorials/mvc-music-store-part-3
In the controller they are passing a list of genres to the view model, I am just a beginner but I feel like it is the viewmodel's job to present the data in what ever format the view requires.
the tutorial code does this...
public ActionResult Index()
{
// Retrieve list of Genres from database
var genres = from genre in storeDB.Genres select genre.Name;
// Set up our ViewModel
var viewModel = new StoreIndexViewModel()
{
Genres = genres.ToList(),
NumberOfGenres = genres.Count()
};
// Return the view
return View(viewModel);
}
What I want to do is pass genres to the viewModel and inside the viewModel create the list as well as set the NumberOfGenres property. The way this is coded the controller has to know more about the view than it needs to.
can someone show me what my viewModel class would look like in order to use the ToList() and Count() methods on the genres property inside my viewModel ?