表单标签在foreach循环剃须刀MVC 3中消失 [英] form tag disappear in foreach loop razor MVC 3
本文介绍了表单标签在foreach循环剃须刀MVC 3中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在razor的foreach循环中使用表单标签时遇到问题,当它呈现输出html错误时,因为在第一次迭代中表单标签消失了,这是剃刀代码
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>
}
这是呈现的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:
<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
这篇关于表单标签在foreach循环剃须刀MVC 3中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文