我想通过 ajax 和 jQuery 在我的控制器中调用一个方法,并分析success
回调中的响应。但我想向这个响应发送一个部分视图数组,如下例所示:
$.ajax({
url: '/Admin/Design/ChangeQuestionType',
type: 'POST',
data: {
viewname: viewname,
questionid: questionid,
questiontypeid:questiontypeid,
pageid: pageid
},
success: function (response) {
jQuery.each(response, function (i) {
console.log(response);
$('.questionvalidation').html(response[i])
});
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
console.log(xhr.responseText);
alert(thrownError);
}
});
控制器是:
public ActionResult ChangeQuestionType(string viewname, int questionid, int questiontypeid, int pageid)
{
var viewbody = PartialView(viewname);
var viewtitle = PartialView("Title");
List<ActionResult> responselist = new List<ActionResult>();
responselist.Add(viewbody);
responselist.Add(viewtitle);
return Json(responselist, JsonRequestBehavior.AllowGet);
}
执行代码时console.log()
输出: