我正在使用以下代码动态生成控件并将其值插入数据库中,并且它运行良好。问题是我也想起诉同一个视图来返回和更新记录。
@for (var i = 0; i < Model.Attribute_Count; ++i)
{
<tbody id="attribute-row">
<tr>
<td class="left">
@Html.TextBoxFor(x => x.AttributeName[i])
<div class="validation-area">
@Html.ValidationMessageFor(x => x.AttributeName[i])
</div>
</td>
<td class="right">@Html.TextBoxFor(x => x.Attribute_SortOrder[i])</td>
<td class="left"><a onclick="$('#attribute-row' + i).remove();" class="button">-</a></td>
</tr>
</tbody>
}
Jquery的:
var attribute_row = 1;
function addattribute() {
html = '<tbody id="attribute-row' + attribute_row + '">';
html += ' <tr>';
html += ' <td class="left">@Html.TextBoxFor(x=>x.AttributeName)<div class="validation-area">@Html.ValidationMessageFor(x => x.AttributeName)</div></td>';
html += ' <td class="right"><input type="text" name="Attribute_SortOrder" id="Attribute_SortOrder"></td>';
html += ' <td class="left"><a onclick="$(\'#attribute-row' + attribute_row + '\').remove();" class="button">-</a></td>';
html += ' </tr>';
html += '</tbody>';
$('#attribute tfoot').before(html);
attribute_row++;
$('#Attribute_Count').val(attribute_row);
}