gpt4 book ai didi

javascript - MVC Controller 方法不是从 ajax 调用的

转载 作者:行者123 更新时间:2023-12-03 08:42:13 25 4
gpt4 key购买 nike

MVC Controller 方法不是从我声明的 ajax 中调用的。 PFB 代码片段C# Controller :

public ActionResult Checkfunction(string ReqID, string AssociateId, string AssetId)
{
MyDetails obj = new MyDetails();
List<string> Lst = new List<string>();
Lst = obj.Check(AssociateId, AssetId, ReqID);
return this.Json(Lst, "text/json");
}

Javascript代码(ajax调用):引用细节 Controller 和Web方法Checkfunction

$.ajax({
type: 'GET',
cache: false,
url: '@Url.Action("Details/Checkfunction")',
data: { 'ReqID': RequestId, 'AssociateId': AssociateID, 'AssetId': Host_Name },
contentType: "application/json",
success: function (data) {
debugger;
if (data.length > 0) {

ViewModel.REQUESTID() = data[0];
ViewModel.FLAG() = '1';
}
else {
debugger;
ViewModel.FLAG() = '0';
ViewModel.REQUESTID() = '';
}

if (ViewModel.REQUESTID() != '' || ViewModel.REQUESTID() != null) {
debugger;
ViewModel.REQID() = RequestId;
}
},

error: function (error) {
alert("error");
}
});

最佳答案

试试这个:

$.ajax({
type: 'POST',
cache: false,
url: '/PhoenixInbox/Checkfunction',
data: { 'ReqID': RequestId, 'AssociateId': AssociateID, 'AssetId': Host_Name },
contentType: "application/json",
success: function (data) {
debugger;
if (data.length > 0) {

ViewModel.REQUESTID() = data[0];
ViewModel.FLAG() = '1';
}
else {
debugger;
ViewModel.FLAG() = '0';
ViewModel.REQUESTID() = '';
}

if (ViewModel.REQUESTID() != '' || ViewModel.REQUESTID() != null) {
debugger;
ViewModel.REQID() = RequestId;
}
},

error: function (error) {
alert(JSON.stringify(error));
}
});

Controller :

[Httppost]
public ActionResult Checkfunction(string ReqID, string AssociateId, string AssetId)
{
MyDetails obj = new MyDetails();
List<string> Lst = new List<string>();
Lst = objMyAssetsDetails.Check(AssociateId, AssetId, ReqID);
return this.Json(Lst, "text/json");
}

关于javascript - MVC Controller 方法不是从 ajax 调用的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33016528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com