I am created a application in MVC3 and I want to reload the partial view on button click, but partial view is not updating.
ActionResult Method
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);
}
Partial View inside Main View
<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');
}
});
It always goes in error section.
Anyone can help me.
url: "/Comments/CommentForPost/" + postIdwithoutdata: d,and why do you usePOSTrequest for this? As per your action you should doGETrequestsuccess: function (r), but you try insert$('#dvPostedComment').html(data);CommentForPost?