Parameter question returning a View

May 30, 2010 at 11:24 AM

Hi all,

first of all, I would like to thank the guys who created this tutorial, it turned out a big help to learn MVC 2 for me. However, I have found a point that I do not understand completely, so I hope you can lend a hand to me.

It is in the page 43 of the tutorial:


public ActionResult Index()
var albums = storeDB.Albums
return View(storeDB.Albums);

 should not this line "return View(storeDB.Albums);" be "return View(albums);" ? If not, why have we created the albums variable?

Thanks in advance!!!


May 30, 2010 at 3:15 PM
Edited May 30, 2010 at 3:17 PM

I believe you are correct--despite the fact the the source code also contains this syntax.

I tried it both ways, and the StoreManager Index page works the same with each, but when using the

return View(storeDB.Albums);

syntax, clicking on "Edit" (on the StoreManager Index page) results in this kind of error:

The model item passed into the dictionary is of type 'System.Data.Objects.ObjectSet`1[storeDB.Models.Album]', but this dictionary requires a model item of type 'MvcMusicStore.ViewModels.StoreManagerViewModel'.

 This error seems to make sense, since our Edit template inherits the StoreManagerViewModel and not the storeDB model.

Jul 2, 2010 at 8:54 PM

@Mihe - You're correct, this is an error in the tutorial. It should be returning albums, not storeDB.Albums. That correction will be in the next release.