【发布时间】:2019-12-17 09:06:15
【问题描述】:
我有这个 AJAX 调用,我试图在我的项目中调用部分视图。
function ImportBundle() {
var req = { "from": "bundle" };
$.ajax({
async: true,
type: "GET",
url: "Client/ZWS/{lang}/ImportBundles",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(req),
dataType: 'html',
success: function (data) {
$(".viewdiv").html(data);
},
failuere: function () { alert("fail"); }
});
}
这是我的项目控制器:
[System.Web.Http.HttpGet]
public ActionResult ImportBundles([FromUri] string from)
{
return PartialView("~/Views/_ViewImportBundles.cshtml");
}
但是,当我调试应用程序时,我得到了 null。
知道为什么吗?谢谢!
【问题讨论】:
-
您是否尝试将数据放入变量中? data: {someVar : JSON.stringify(req) } 那就是你的控制器变量名 ImportBundles(string someVar)
-
像这样: var req = { "from": "bundle" };数据:{ myVar : JSON.stringify(req) } ?
-
也试过了。不工作:(
-
您是否尝试过使用 url: "Client/ZWS/{lang}/ImportBundles?from=bundle" ?在 GET 请求中,您将参数作为查询字符串的一部分传递。
-
你知道控制器是否被调用了吗?在其中设置一个断点。可能是网址错误。
标签: asp.net json ajax asp.net-mvc model-view-controller