形式标记在foreach循环剃刀消失MVC 3

问题描述:

我有在剃刀foreach循环形式的标签的问题,当渲染输出HTML是错误的,因为在第一次迭代的形式标记消失,这里的剃刀代码形式标记在foreach循环剃刀消失MVC 3

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

+0

您呈现的HTML包含'form'标签。 –

+0

不在第一次迭代中,它只包含第二个

中的表格标签,而不是第一个 – Overmachine

回答

你可能会试图启动一个现有的内部新的标签,就像这样:

<form id="mainPageForm"> 
@foreach(item in items) 
{ 
    <form id="[email protected](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 
+1

那么您是如何解决这个问题的? – Sun

你可能会试图启动一个现有的内部新的标签,就像这样:

<form id="mainPageForm"> 
@foreach(item in items) 
{ 
    <form id="[email protected](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 
+1

那么您是如何解决这个问题的? – Sun

你可能会试图启动一个现有的内部新的标签,就像这样:

<form id="mainPageForm"> 
@foreach(item in items) 
{ 
    <form id="[email protected](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 
+1

那么您是如何解决这个问题的? – Sun