Bind javascript to controller model

marcos.marchette

New member
Joined
May 3, 2024
Messages
2
Programming Experience
10+
Guys, good morning
I have a problem with binding javascript via ajax to controller

I have a model that internally groups other models:
C#:
 public class OFViewModel
 {
 public OpcaoServico OpcaoServico { get; set; }

 public string UserLogged { get; set; }

 public OFCottacaoViewModel OFFCotacaoViewModel { get; set; }

 public OFBecalhoViewModel OFBecalhoViewModel { get; set; }

 public OFItemViewModel OFItemViewModel { get; set; }
}

I have my javascript function that uses Ajax as a request ex:
JavaScript:
function PutEditItemValueQty() {

let return = buildOFViewModel();

let oFViewModelTeste = return;

 UCallAjaxWithJson("/SupplyChain/OFItem/PutEditarQtdeValorItem", "PUT", oFViewModelTeste)
 .then((data) => {
 if (data.isSuccess) {

 //let return = data.result
 //for (var i = 0; i < return.length; i++) {
 // emails = emails + return[i].eroeema + ";"
 //}

 } else if (data.retornoAjax === "warning") {
 UMsgAjax(date);
 } else if (data.retornoAjax === "info") {
 UMsgAjax(date);
 } else {
 UErrorAjax(date);
 }
 })
 .catch((error) => {
 CheckStatusCode(error);
 });

}
To obtain the sending parameters, I created a function:
JavaScript:
function buildOFViewModel() {
 let obj = {
 ServiceOption: 0,
 LoggedUser: null,
 OFCotacaoViewModel: [{
 Erciefor: 0,
 Erceqraz: null,
 Erceqfan: null,
 Erccbcot: 0,
 Erreqnum: 0,
 Ercititis: 0,
 Erccbcmp: null,
 Erccbemp: 0,
 Erccbfil: 0,
 Erccbifs: 0,
 EmpFilIfs: null
 }],
 OFCabecalhoViewModel: [{
 Erofccod: elemidErofccod.value,
 Erofcemp: elemEmpresa.value,
 Erofcfil: elemFilial.value,
 Erofcifs: 0,
 PhysicalInstallationName: null,
 CompanyBranchInstFis: null,
 CompanyBranchConcatenated: null,
 DescriptionCompanyBranchInstFis: null,
 Erofcapl: null,
 Erofcset: null,
 Erofcfor: 0,
 SupplierNameCode: 0,
 SupplierName: null,
 InvoicedCompanyName: null,
 Invoiced BranchName: null,
 PaymentConditionName: null,
 Erofcemf: 0,
 Erofcfif: 0,
 Erreqnum: 0,
 Erofcobs: null,
 Erofcdco: new Date(),
 Erofcden: new Date(),
 Erofcent: null,
 Erofccie: null,
 Erofcufe: null,
 Erofclde: null,
 Erofctle: null,
 Erofcctr: null,
 Erofcntr: null,
 Erofccif: null,
 Erofcnve: null,
 Erofccpg: 0,
 Erofcosr: null,
 Erofcqto: 0.0,
 Erofcvlm: 0.0,
 Erofcvld: 0.0,
 Erofcvac: 0.0,
 Erofcvfr: 0.0,
 Erofcvse: 0.0,
 Erofcvem: 0.0,
 Erofcals: 0.0,
 Erofcvis: 0.0,
 Erofcvip: 0.0,
 Erofcvof: 0.0,
 Erofcvou: 0.0,
 Erofcdur: new Date(),
 Erofcqre: 0.0,
 Erofcvrr: 0.0,
 Erofcvru: 0.0,
 Erofcqca: 0.0,
 Erofcvca: 0.0,
 Erofcvcu: 0.0,
 Erofcbld: new Date(),
 Erofccmp: null,
 Erofcblo: null,
 Erofcblu: null,
 Status: null,
 Erofcsta: 0,
 CarrierName: null,
 TelephoneContactDelivery: null,
 EncryptedIdOF: null,
 EncryptedRequestId: null,
 DescriptionStatusOF: null,
 Icons: null,
 AssignCode: 0,
 Erofscor: null,
 Erofsdsc: null,
 CnpjFormatted: null,
 }],

 };
 return obj;
}
When making a request to the controller with ajax, the model arrives with empty properties in the controller

NOTE: Some fields are null

Could anyone help me with what I might be doing wrong?
 
Last edited by a moderator:
My suggestion is start with a minimal object model, test, and get it working. Start with an object that contains a single integer. Get that working. Then add a string as another field and get that working. Then next a field that is an array of integers and get that working. Next a field that contains another object. Then a field that is an array of objects. And then a field that is list of integers (instead of an array of integers). The a a field that is a list of objects.
 

Latest posts

Back
Top Bottom