Shouldn't next paragraph say Genre
instead of Album(if not please let me know) to fit the code that comes after?
On Page 58 Last paragraph in View Models
For example, the Album Edit view for the
MVC Music Store needs to populate dropdowns for Genres and Albums in our system, but those
lists donât fi t in the Album model. To handle this without polluting our Album model with extraneous
information, we can pop the Genre and Album information into the ViewBag, as shown in
So the dropdown is about Genre and Album but the list doesn't fit in the Album model?
Then the code change to ViewBagGenre and ViewBagArtistID.
public ActionResult Edit(int id = 0)
Album album = db.Albums.Find(id);
if (album == null)
ViewBag.GenreId = new SelectList(
db.Genres, "GenreId", "Name", album.GenreId);
ViewBag.ArtistId = new SelectList(
db.Artists, "ArtistId", "Name", album.ArtistId);