表格标签在foreach循环剃须刀MVC 3中消失

时间:2012-11-15 18:13:28

标签: html asp.net-mvc-3 razor

我在razor的foreach循环中有一个表单标签有问题,因为在第一次迭代中,表单标签在这里消失的是剃刀代码

@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>

        }

这里是渲染的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>

  

1 个答案:

答案 0 :(得分:4)

您可能正尝试在现有标签内开始新标记,如下所示:

<form id="mainPageForm">
@foreach(item in items)
{
    <form id="nestedForm@(item.FormId)">
}
</form>

结果是这样的:

<form id="mainPageForm">
  <form id="nestedForm1"></form>  --> this ends the first form
  <form id="nestedForm2"></form>  --> correctly formed
  <form id="nestedForm3"></form>  --> correctly formed
</form> --> closing tag without parent