【发布时间】:2014-01-13 16:15:01
【问题描述】:
我正在向现有 div 添加部分视图以添加更多重复的用户字段。我就是这样做的:
<div class="userDiv"> Existing HTML goes here </div>
AND 锚链接以添加另一个用户
@Html.ActionLink("Add another User", "AddUser", null, new { id = "addAnotherUserLink" })
$("#addAnotherUserLink").click(function () {
$.ajax({
url: this.href,
cache: false,
success: function (html) { $(".userDiv").append(" <div class='userPartialDiv'><a href='#' class='deleteRow'>Delete</a>" + html + "</div>"); }
});
return false;
});
当你点击删除时,它会删除附加的局部视图。
$(document).on("click", ".deleteRow", function () {
$(this).closest(".userPartialDiv").remove();
return false;
});
我的问题是如何给它一个数字。 假设我在添加另一个用户按钮上添加或单击了四次,它将向现有 DIV 添加四个局部视图。但我需要给他们一个像 user1、user2、user3、user4 这样的数字。但是当我删除其中一个让我们说第二个时,它应该自动重新排序给 user1,user2,user3,而不是 user1,user3,user4。
还请帮助我如何将这些数据添加到数据库中。我的意思是如何通过循环添加的部分视图的数量将数据从部分视图读取到控制器中。
感谢您的帮助。
谢谢
【问题讨论】:
标签: jquery asp.net-mvc model-view-controller