I need to print this html in a view:
@foreach (string indices in Model.Indices)
{
if (counter == 1)
{
Response.Write("<tr>");
}
Response.Write("<td><span class='select'>@Html.CheckBox('nome',false)</span>)"); @indices Response.Write("</td>");
if (counter > 4)
{
Response.Write("</tr>");
}
}
This will print the html markup which I want to create.
I know I could only write the html but Razor is complaining that I am not closing the foreach.
This was my first try:
@foreach (string indices in Model.Indices)
{
if (counter == 1)
{
<tr>
}
<td><span class='select'>@Html.CheckBox('nome',false)</span> @indices </td>
@if (counter > 4)
{
</tr>
}
}
Razor requires that HTML tags be well-formed; otherwise, it wouldn’t know when to go back to code context.
You can bypass this restriction by prefixing the line with
@:.However, the correct way to do this is to group your collection into a collection of groups of 4 items, and use a nested
foreach.