I am trying to render some DIV inside a table td tag using HTML Helper methods in ASP .net MVC. For some reason, the divs are not being rendered. here is my sample code. My Model has two properties ID and a list of Strings. The strings are basically HTML DIV tags.
<table>
<tr>
<th>ID</th>
<th>Schedule</th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td><%: Html.DisplayFor(modelItem => item.ID) %></td>
<td>
<% foreach (var bar in item.Details)
{
Html.DisplayFor(modelItem => bar);
}
%>
</td>
</tr>
<% } %>
</table>
The view is populated with the ID but not the DIV tags. Can someone point to me what I could be doing wrong.
Thanks,
Javid
You are missing the
<%: %>around theHtml.DisplayForbecause the
Html.DisplayFordoesn’t write directly to the Response just returns the rendered template as aMvcHtmlString, so it’s need to be “outputted” with the<%: %>.