I am taking a JavaScript course at my local trade school to get better at it. This is an intro course....and we have been passing data from JS to our Controller like this
for (i = 0; i <= AddCount; i++) {
var saveInfo = {
Address: $("#streetAddress" + i).val(),
City: $("#City" + i).val()
};
saveData(saveInfo);
now our bonus for the week is to translate this example into the above syntax....
My thought is to code it just like this but I"m not sure if I fully understand....
var saveInfo = { beenVerified: beenVerified, streetAddress: streetAddress };
update(saveInfo);
Does this look right to people more versed in JavaScript?
I think what needs to be done is to not pass in individual variables, but to pass in an array that contains all the variables. Which is why I did it the way I did in the 3rd code sample....
Does this look right to people more versed in JavaScript?
I think you are right, if i'm not understanding anything here.
After you get the value from the second part of code, set the value as your third part of code and use this object saveInfo in your update(obj) method.
Member
44 Points
118 Posts
Parameter Passing From javascript To C# MVC Controller
Oct 31, 2019 12:11 AM|LiarLiarPantsOnFire|LINK
I am taking a JavaScript course at my local trade school to get better at it. This is an intro course....and we have been passing data from JS to our Controller like this
now our bonus for the week is to translate this example into the above syntax....
My thought is to code it just like this but I"m not sure if I fully understand....
Does this look right to people more versed in JavaScript?
I think what needs to be done is to not pass in individual variables, but to pass in an array that contains all the variables. Which is why I did it the way I did in the 3rd code sample....
Participant
1750 Points
568 Posts
Re: Parameter Passing From javascript To C# MVC Controller
Oct 31, 2019 05:27 AM|Yang Shen|LINK
Hi LiarLiarPantsOnFire,
I think you are right, if i'm not understanding anything here.
After you get the value from the second part of code, set the value as your third part of code and use this object saveInfo in your update(obj) method.
I did a little test at Object initializer, it seems works well.
Best Regard,
Yang Shen