I don't see the list of genres from Model.Genres

Jan 10, 2011 at 1:12 PM
Edited Jan 10, 2011 at 1:13 PM

Hi,

I using the following code (Index.aspx):

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h3>Browse Genres</h3>

    <p>Select from <%: Model.NumberOfGenres %> genres:</p>

    <ul>
        <% foreach (string genreName in Model.Genres)
           {  %>
        <li>        
           <% Html.ActionLink(genreName, "Browse", new { genre = genreName }); %>
        </li>
        <%} %>
    </ul>

</asp:Content>

 The foreach is not bringing any data. Any clue? Thank you in advance.

Jan 10, 2011 at 1:27 PM

I see the problem. I forgot the <%: here

<%: Html.ActionLink(genreName, "Browse", new { genre = genreName }); %>

Coordinator
Jan 10, 2011 at 6:11 PM

Yes, that : is important! Otherwise the code will be executed, create the HTML for all the links, and then throw it away since you haven't told ASP.NET to display it.

<% %> just executes code
<%: %> executes code and displays the result 

Jan 11, 2011 at 2:51 PM

Hi jongalloway,

Thank you for the explanation. Regards.