1

我在 razor 的 foreach 循环中出现表单标签的问题,当它呈现输出 html 时是错误的,因为在第一次迭代中,表单标签消失在这里是 razor 代码

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

4

1 回答 1

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
于 2012-11-28T15:05:55.543 回答