下面是我的cshtml代码
我在主视图中使用了IEnumerable,在局部视图中使用了单个模型对象
即时进行CRUD操作......每行都有编辑/详细信息/删除按钮
@model IEnumerable<jQuery_CRUD.DAL.User>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.DisplayFor(modelItem => item.ContactNo)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.UserId }, new { @class = "modal-with-form btn btn-default" ,href = "#modalEdit" }) |
@Html.ActionLink("Details", "Details", new { id = item.UserId }, new { @class = "modal-with-form btn btn-default", href = "#modalDetails" }) |
@Html.ActionLink("Delete", "Delete", new { id = item.UserId }, new { @class = "modal-with-form btn btn-default", href = "#modalDelete" })
<div id="modalEdit" class="modal-block modal-block-primary mfp-hide">
@Html.Partial("Edit", item)
</div>
<div id="modalDetails" class="modal-block modal-block-primary mfp-hide">
@Html.Partial("Details", item)
</div>
<div id="modalDelete" class="modal-block modal-block-primary mfp-hide">
@Html.Partial("Delete", item)
</div>
</td>
</tr>
单击编辑/详细信息仅显示表格中第一行的信息
我使用的局部视图中的模型是
@model jQuery_CRUD.DAL.User
我是否克服了这个
答案 0 :(得分:0)
这是因为您在表格中为每个id
重复使用相同的item
属性,而元素id
应该是唯一的。
使用item.UserId
为每个人分配一个唯一的id
:
@Html.ActionLink("Edit", "Edit", new { id = item.UserId }, new { href = "#modalEdit" + item.UserId }) |
@Html.ActionLink("Details", "Details", new { id = item.UserId }, new { href = "#modalDetails" + item.UserId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.UserId }, new { href = "#modalDelete" + item.UserId })
<div id="modalEdit@(item.UserId)" class="modal-block modal-block-primary mfp-hide">
@Html.Partial("Edit", item)
</div>
<div id="modalDetails@(item.UserId)" class="modal-block modal-block-primary mfp-hide">
@Html.Partial("Details", item)
</div>
<div id="modalDelete@(item.UserId)" class="modal-block modal-block-primary mfp-hide">
@Html.Partial("Delete", item)
</div>