I have a problem with form tags in a foreach loop in razor when it render the output html is wrong because in the first iteration the form tags disappear here is the razor code
@foreach (var item in Model)
{
<tr>
<td>@if (item.IsMandatory)
{
<span class="label label-important">Obligatorio</span>
}
else
{
<span class="label">Opcional</span>
} </td>
<td>@Html.DisplayFor(modelItem => item.DocumentName)</td>
<td>
</td>
<td>
<form>
form here!
</form>
</td>
</tr>
}
here is the rendered html:
<table class="table table-striped">
<thead>
<tr>
<th>Requerido</th>
<th>Documento</th>
<th>Accion</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span class="label label-important">Obligatorio</span>
</td>
<td>Copia de cédula</td>
<td>
here form! <----------Problem Here
</td>
</tr>
<tr>
<td>
<span class="label label-important">Obligatorio</span>
</td>
<td>
Copia de otro documento de identidad (licencia, pasaporte, seguro)
</td>
<td>
<form novalidate="novalidate">
here form!
</form>
</td>
</tr>
You’re probably trying to start a new tag inside an existing one, like this:
Which results in something like this: