从$ .Ajax Post返回PartialView
我有以下代码;
$.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); }
在我的控制器;
[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); } }
除非它被复制错误,否则看起来你错过了一些结束令牌。
$.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); } //<-- added close for anonymous function }); //<--added close/semicolon for ajax function
此外,您正在POST,但您的操作似乎没有[Post]属性。 当您在调试器中运行此操作时,您的操作的断点会被命中吗?