Problem in views - MvcMusicStore.Models.Artist

Sep 12, 2010 at 5:44 PM

Hello,

In my /storemanager when I show the album list with all my albuns I get this result:

Index


Title Artist Genre
Edit | Details | Delete For Those About To Rock We Salute You MvcMusicStore.Models.Artist MvcMusicStore.Models.Genre
Edit | Details | Delete Let There Be Rock MvcMusicStore.Models.Artist MvcMusicStore.Models.Genre
Edit | Details | Delete Greatest Hits MvcMusicStore.Models.Artist MvcMusicStore.Models.Genre
Edit | Details | Delete Misplaced Childhood MvcMusicStore.Models.Artist MvcMusicStore.Models.Genre
Edit | Details | Delete The Best Of Men At Work MvcMusicStore.Models.Artist MvcMusicStore.Models.Genre

 

The title is good, but under Artist and Genre I get MvcMusicStore.Models.Artist and MvcMusicStore.Models.Genre. I don't know how to resolve this.

Any help would be appreciated.

André

 

 

Coordinator
Sep 13, 2010 at 6:48 PM

It looks like your view code for /Views/StoreManager/Index.aspx is incorrect. I'm guessing you've got this:

    <% foreach (var item in Model) { %>
        <tr>
            <td>
                <%: Html.ActionLink("Edit", "Edit", new { id=item.AlbumId }) %> |
                <%: Html.ActionLink("Delete", "Delete", new { id=item.AlbumId })%>
            </td>
            <td><%: Html.Truncate(item.Title, 25) %></td>
            <td><%: item.Artist %></td>
            <td><%: item.Genre %></td>
        </tr>
    
    <% } %>

You need to use item.Artist.Name and item.Genre.Name, like this:

    <% foreach (var item in Model) { %>
        <tr>
            <td>
                <%: Html.ActionLink("Edit", "Edit", new { id=item.AlbumId }) %> |
                <%: Html.ActionLink("Delete", "Delete", new { id=item.AlbumId })%>
            </td>
            <td><%: Html.Truncate(item.Title, 25) %></td>
            <td><%: item.Artist.Name %></td>
            <td><%: item.Genre.Name %></td>
        </tr>
    
    <% } %>

 


Sep 13, 2010 at 10:15 PM

Thank you very much jongalloway! That was exactly the problem.

These type of tutorials really help! I appreciate all the effort put into this.

What are advantages for using MVC over webforms?

Thanks