我在 asp.net mvc3 中遇到 ajax 更新 div 的问题。
我有一个包含内容的视图
<div id="post_comments">
@{Html.RenderPartial("_RefreshComments", Model);}
</div>
<div id="commentForm">
@using (Ajax.BeginForm("Details", new { id = Model.Post.PostId }, new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "post_comments"
}
))
{
// form content goes here
<p id="buttons">
<input type="submit" value="@Strings.Save" />
</p>
}
这是我的部分观点
@model Project.Models.Posts.PostDetailsViewModel
@{
foreach (var c in Model.ApprovedComments)
{
@Html.DisplayFor(x => c)
}
}
我有一个控制器
public ActionResult Details(int id, FormCollection form )
{
var model = new PostDetailsViewModel(UnitOfWork, id);
return PartialView("_RefreshComments", model);
}
我的布局cshtml中包含以下脚本
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
并且
<appSettings>
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
它确实有效,我可以添加评论,但控制器只返回 PartialView,不包含在布局中。我发现ASP.net MVC3 - Razor Views and PartialViews with Ajax Postbacks但从那里没有任何帮助。
有没有人有任何想法?