gpt4 book ai didi

asp.net-mvc - 从 $.Ajax Post 返回 PartialView

转载 作者:行者123 更新时间:2023-12-03 21:54:37 24 4
gpt4 key购买 nike

我有以下代码;

        $.ajax({
url: "/Home/jQueryAddComment",
type: "POST",
dataType: "json",
data: json,
contentType: 'application/json; charset=utf-8',
success: function(data){
//var message = data.Message;
alert(data);
$('.CommentSection').html(data);
}

在我的 Controller 中;

    [ValidateInput(false)]
public ActionResult jQueryAddComment(Comment comment)
{
CommentSection commentSection = new CommentSection();

//ya da - ya da
// fill the commentsection object with data

//then
return PartialView("CommentSection", commentSection);

}

但是,当我返回页面时,成功警报并未发生。谁能看出这个逻辑中的缺陷吗?

最佳答案

您在 .Ajax POST 中期待 JSON,但在 ActionMethod 中您返回 PartialView

尝试:

$.ajax({
url: "/Home/jQueryAddComment",
type: "POST",
dataType: "html",
data: json,
success: function(data){
//var message = data.Message;
alert(data);
$('.CommentSection').html(data);
}
}

关于asp.net-mvc - 从 $.Ajax Post 返回 PartialView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3490059/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com