JQuery Ajax,没有回调函数在ASP.NET MVC 5中运行

Mar*_*son 7 ajax asp.net-mvc jquery

我正在尝试使用JQuery Ajax在容器div中呈现局部视图.这是我的ajax电话:

var href = {
    href: $(this).attr("href").substr(1)
}
var container = $(".customer-main-content-container");
$.ajax({
    url: "@Url.Action(" CustomerMenuSelection ")",
    type: "POST",
    dataType: "html",
    contentType: "application/json",
    data: JSON.stringify(href),
    error: function (jqXHR, textStatus, errorThrown) {
        alert("ERROR: " + errorThrown.text());
    },
    success: function (result) {
        container.empty();
        container.html(result).show();

    }
});
Run Code Online (Sandbox Code Playgroud)

更新

这是我的行动代码:

public ActionResult CustomerMenuSelection(string href)
{
    var user = GetCurrentUser();
    var tempSensorTree = _prtgClient.GetPrtgSensorTree(user.TempPrtgGroupId.ToString());
    var tempDevices = tempSensorTree.Sensortree.Nodes.Group.Device;

    return PartialView("_Monitor", tempDevices);
}
Run Code Online (Sandbox Code Playgroud)

我通过我的Action跟踪了调用,发现它确实将所有正确的数据发送回视图.但是,我的ajax调用没有运行错误或成功回调,我不知道为什么.单击菜单项时会发生这种情况,同样的ajax-call适用于除此之外的所有其他菜单项.我找不到页面之间的任何差异.不会抛出任何错误,我填充视图的数据是正确的.我的ajax电话刚刚停止.

简而言之,为什么我的回调没有被触发?

感谢任何帮助!在此先感谢Martin Johansson

Nit*_*rpe 1

出现此问题可能是因为dataType您对服务器有期望。尝试将其更改为"html"从服务器返回部分视图。

dataType: "html"
Run Code Online (Sandbox Code Playgroud)