加载ajax导致布局 [英] Loading of ajax result in layout
本文介绍了加载ajax导致布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Asp.NET核心的布局页面中,我正在尝试加载AJAX发布的结果.状态正常,但出现错误:
In the Asp.NET core's layout page, I'm trying to load the result of an AJAX post. Status is OK but comes as an error:
_Layout.cshtml
_Layout.cshtml
<div id="MainContentDiv">
@RenderBody()
</div>
$.ajax({
type: 'POST',
url: '/Something/LoadView',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({ ... }),
error: function (result) {
console.log("error");
console.log(result);
},
success: function (result) {
$("#MainContentDiv").html(result);
}
[HttpPost]
public ActionResult LoadView([FromBody] NodeData model)
{
string action= "Index";
switch(model.NodeType)
{
case StringConstants.something:
action = "GData";
break;
// ...
}
return RedirectToAction(action, "Some", model);
}
public PartialViewResult GData(NodeData model)
{
// ...
return PartialView("_GroupsData", group);
}
响应
推荐答案
dataType
您是在告诉jQuery期望什么样的响应.
dataType
is you telling jQuery what kind of response to expect.
由于您从服务器返回了html而不是json结果,请尝试直接在ajax中删除dataType: 'json'
.请参考 ajax数据类型
Since you return html instead of json result from server,try to remove the dataType: 'json'
in your ajax directly. Refer to ajax dataType
$.ajax({
type: 'POST',
url: '/Something/LoadView',
//dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({ ... }),
error: function (result) {
console.log("error");
console.log(result);
},
success: function (result) {
$("#MainContentDiv").html(result);
}
});
这篇关于加载ajax导致布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文