gpt4 book ai didi

javascript - 通过 ajax 传递数据 - 参数字典包含参数的空条目

转载 作者:行者123 更新时间:2023-11-28 00:23:21 25 4
gpt4 key购买 nike

我得到了之前的问题,这与我之前的问题完全相同。 Passing data from ajax to mvc controller - null parameter error

之后我们更改了界面和 JavaScript 中的一些内容。所以现在当我尝试在服务器上传递数据时出现此错误

The parameters dictionary contains a null entry for parameter 'method' of non-nullable type 'API.PVT.Solver.Methods' for method 'System.Web.Mvc.ActionResult StandartModelResult(API.PVT.Solver.InputDataModel, API.PVT.Solver.Methods, API.PVT.Solver.DefaultConstants)' in 'WebServices.Controllers.PVT.PVTMethodsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter

这是我的客户端请求

 GetServerData:function(inputData) {
var outputData;
$.ajax({
type: 'POST',
url: "/PVTMethods/StandartModelResult",
data: JSON.stringify(inputData),
success: function (data) {
outputData = data.result;
appl.PlotData = data.result;
},
error: function (data) {
console.log("Error" + data);
},
dataType: "json",
contentType: "appllication/json; charset=utf-8",
});
return outputData;

}

enter image description here

这是 json 的样子:

"{"method":"eMcCain","model":{"task":"eBw","temperatureRanges":{"Start":200,"End":1000,"Samples":30}},"constants":{"ProducedGOR":500,"OilGravity":35,"SeparatorGasGravity":0.7,"StockTankOilGravity":0.84985,"WaterSalinity":20}}"

这是服务器端模型

  public class DefaultRanges
{
public virtual double Start { get; set; } //начало отрезка
public virtual double End { get; set; } //конец отрезка
public virtual double Samples { get; set; } //шаги
}
//константы
public class DefaultConstants
{
public virtual double ProducedGOR { get; set; }
public virtual double OilGravity { get; set; }
public virtual double SeparatorGasGravity { get; set; }
public virtual double StockTankOilGravity { get; set; }
public virtual double WaterSalinity { get; set; }
}

//pressure rate (pisa)
public class PressureDefaultRanges : DefaultRanges { }

//temperature ranges (Фаренгейты если чо)
public class TemperatureDefaultRanges : DefaultRanges { }

public class PlotRanges : DefaultRanges
{
public virtual double PlotConstant { get; set; } //GOR или Pressure
}
// w\ pressure
public class PlotRangesWP : PlotRanges
{
public virtual double Pressure { get; set; }
}
// w\ GOR
public class PlotRangesWGOR : PlotRanges
{
public virtual double GOR { get; set; }
}

//решаемые задачи
public enum Tasks { ePb, eRs, eBo, eBg, eMo, eMg, eMod, eBw, eMw, eRsw };
//применяемые методы
public enum Methods
{
eAbdulMajeed,//+
eAlShammasi,//+
eAlKhafaji,//+
eAlMarhoun,//+
eAlMarhounSA,//+
eAlmehaideb,//+
eAlNajjaretal,/
eAziz,//+
eBeal,//+
eBeggsRobinson,//+
eBeggsVazquez,//+
eBergman,//+
eDempsey,//+
eDindorukChristman,//+
eDoklaOsman,//+
eElam,//+
eElsharkawy,
eFarshad,//+
eGlaso,//+
eHasan,//+
eKartoatmodjoSchmidt,//+
eKhairy,//+
eKhanEtAl,//dead oil viscosity пока не нужен
eLabediL,//+
eLabediNA,//+
eLasater,//+
eLeeGonzales,//+
eLevitanMurtha,//+
eLucas,//+
eMcCain,//+
eMakary,//+
eObomanuOkpobiri,
eOmarTodd,//+
eOwolabiCI,//+
eOwolabiNS,//+
ePetrosky,//+
eSchlumbergerKuwait,//?
eStanding//+
};




public class InputDataModel
{

public Tasks task { get; set; }

public PressureDefaultRanges pressureRanges { get; set; }

public TemperatureDefaultRanges temperatureRanges { get; set; }

public PlotRanges currentTaskPlotRanges { get; set; }
public double plotConstant { get; set; }
}

这是服务器端 Controller 方法

 public ActionResult StandartModelResult(InputDataModel model , Methods method, DefaultConstants constants = null)
{
SolverInit(constants);

SetDeafultSettings(); //стандартные настройки методов
//var method = Methods.eMcCain;
PVTMethodsSolver.PVTSolverTaskMethodSettings(model.task, method);

var currentResult = resultArray(model);

return Json(new { result = currentResult, status = "ok"}, JsonRequestBehavior.AllowGet);

}

这里出了什么问题?现在甚至无法到达服务器,我的意思是请求。有什么帮助?

最佳答案

像这样更改ajax代码,它就开始工作了

GetServerData:function(inputData) {
var outputData;
$.ajax({
type: 'POST',
async: false,
url: "/PVTMethods/StandartModelResult",
data: inputData,
// async: true,
success: function (data) {
outputData = data.result;
appl.PlotData = data.result;
},
error: function (data) {
console.log("Error" + data);
},
dataType: "json",
// contentType: "appllication/json; charset=utf-8"
});
return outputData;

}

关于javascript - 通过 ajax 传递数据 - 参数字典包含参数的空条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29785622/

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