【发布时间】:2015-01-05 15:36:48
【问题描述】:
我在 MVC3 中创建了一个应用程序,我想在单击按钮时重新加载局部视图,但局部视图没有更新。
ActionResult 方法
public ActionResult CommentForPost(int postId)
{
var PostComments = _commentsRepository.GetCommentsByPostID(postId).Select(u => new CommentsViewModel()
{
CommentUserFullName = u.CommentUserFullName,
CommenterEmailId = u.CommenterEmailId,
CommenterSite = u.CommenterSite,
}).ToList();
return PartialView("PostedComments",PostComments);
}
主视图内的部分视图
<div id="dvPostedComment">
@Html.Partial("PostedComments", Model.Post)
</div>
jQuery
var postId = $("#hdnPostId").val();
var d = "postId=" + postId;
$.ajax({
type: "POST",
url: "/Comments/CommentForPost",
data: d,
success: function (r) {
$('#dvPostedComment').html(data);
},
complete: function () {
alert('hello2');
},
error: function (req, status, error) {
alert('helll3');
}
});
它总是进入错误部分。
任何人都可以帮助我。
【问题讨论】:
-
在没有
data: d,的情况下尝试url: "/Comments/CommentForPost/" + postId,你为什么使用POST请求这个?根据您的操作,您应该执行GETrequest -
在你的代码
success: function (r),但你尝试插入$('#dvPostedComment').html(data); -
能否提供错误信息和状态?
-
Hi Grundy... 错误:内部服务器错误和状态:阻止此页面创建其他对话框。
-
您是否尝试在您的
CommentForPost中设置断点?
标签: jquery asp.net-mvc-3