Album and Artist on Detail page

May 11, 2011 at 7:14 AM

Hello,

After creating the Store Manager Controller (p. 55 in the PDF) and navigating to the Detail page, I noticed that just the labels for "Artist" and "Album" show up, but the data for each is not displayed as it is on the Store Manager index page.

When you look at 'StoreManager/Details.cshtml' the following code is there:

<div class="display-label">Company</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Company.Name)
    </div>

    <div class="display-label">Category</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Category.Name)
    </div>

Can anyone point me in the right direction as to how to modify the code so that the actual "Artist" and "Album" values are displayed? The same goes for the 'Delete' page.

Thanks!

Coordinator
May 11, 2011 at 9:16 PM
Edited May 11, 2011 at 9:17 PM

It looks like you've built those views against a Company model rather than the Album model. I would delete the controller and views, then re-add them, making sure you've selected the correct Model class, as shown below:

Alternatively, you can compare your StoreManager views against the StoreManager views in the completed project.

May 12, 2011 at 2:35 AM
Edited May 12, 2011 at 2:46 AM

Thanks for the reply. I should have explained my code sample better. While going through the tutorial I followed all of the steps, but instead of a music store I made mine a 'Job Tracker' application. So I changed the name of certain classes like this:

Artist > Company
Genre > Job Category
Album > Job

So I built those views against my 'Job' model, consistent with building against the 'Album' model in the directions. I noticed that in the tutorial, the 'Artist' and 'Genre' also do not show up on the detail and delete pages. I think it has something to do with the fact that 'Artist.Name' and 'Genre.Name' are defined outside of the Album class (which detail.cshtml imports), but I can't figure out how to access those from detail.cshtml.


And by looking at the code from 'Detail.cshtml' from the finished application, it looks like those values are expected to show:

    <div class="display-label">Genre</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Genre.Name)
    </div>

    <div class="display-label">Artist</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Artist.Name)
    </div>

 

THanks.

May 13, 2011 at 8:30 AM
Edited May 13, 2011 at 8:31 AM

Ok, the above issue gets resolved at the point in the tutorial when you mark the Genre and Artist as virtual properties. I'm still not exactly sure why this is, but after adding the 'virtual' keyword, the Genre and Artist fields are displayed normally in the StoreManager 'Details' and 'Delete' views.

Thanks,
Jonathan