我想在我的表单中添加一些 ajax。这是主要视图:
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
// here I display each post from Posts collection
@foreach (var post in Model.Posts)
{
<div>
<div>
<strong>
Title: @post.Title
</strong>
</div>
<div>@post.Text</div>
<div>Posted by: @post.User.UserName</div>
<div>Posted Date: @post.CreatedDate</div>
@{ var membershipUser = Membership.GetUser(); }
@if (membershipUser != null)
{
var providerUserKey = membershipUser.ProviderUserKey;
if (providerUserKey != null && post.CreatedBy == (Guid) providerUserKey)
{
<div style="display: none; color: red;" id="postEditLoading">Loading..</div>
<p id="postEdit">
// EditPost method returns edit view asynchronously
@Ajax.ActionLink("Edit", "EditPost", new {id = post.PostId, @class = "averageLink"},
new AjaxOptions {UpdateTargetId = "postEdit", LoadingElementId = "postEditLoading", LoadingElementDuration = 3000})
@Html.ActionLink("Delete", "DeletePost", new {id = post.PostId}, new {@class = "averageLink"})
</p>
}
}
一切正常,除了这个奇怪的事情:EditPost 方法返回的表单出现在第一篇文章的正下方,无论我想编辑第一篇还是最后一篇。
我该如何解决这个问题,所以表格会出现在我要编辑的帖子下方?
提前感谢您的帮助!