有内环路相同的ID与MVC TextBoxFor [英] MVC with TextBoxFor having same id within loop

查看:112
本文介绍了有内环路相同的ID与MVC TextBoxFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个表单中的一个表,一个更新按钮。理想的情况是每个行会是一种形式,但是,这并不符合HTML规范。

I would like to have a table within a form, with an update button. Ideally each row would be a form, but that doesn't fit html spec.

我的看法是这样的。

@model IEnumerable<DabTrial.Models.ManageFilesModel>

@foreach(var item in Model) {
<tr>
    <td>
        @Html.TextBoxFor(modelItem=>item.Name)
        ....

当我在看的标记,同一属性每一行中输入具有相同的ID

when I look at the markup, the inputs within each row for the same property have the same id

<input id="item_Name" type="text" value="ParentGuardianPMH.pdf" name="item.Name">
...
<input id="item_Name" type="text" value="ParentGuardianMMH.pdf" name="item.Name">

这显然是无效的 - 我应该怎么做这个。谢谢

which is obviously invalid - how should I be doing this. Thank you

推荐答案

使用循环,而不是一个的foreach ,你就会有明显的标识。

use a for loop, not a foreach, and you'll have distinct id.

这篇关于有内环路相同的ID与MVC TextBoxFor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆