Parameter Passing From javascript To C# MVC Controller RRS feed

  • Question

  • User974100899 posted

    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()

    now our bonus for the week is to translate this example into the above syntax.... 

    $(this).find("td").each(function() {
    if($(this).find('input').is(':checked')) {
    beenVerified ='on'; 
    beenVerified ='off'; 
    streetAddress = $(this).find('input.streetAddress').val(); 
    update(streetAddress, beenVerified); 

    My thought is to code it just like this but I"m not sure if I fully understand.... 

    var saveInfo = { beenVerified: beenVerified, streetAddress: streetAddress };

     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....

    Thursday, October 31, 2019 12:11 AM


  • User-719153870 posted

    Hi LiarLiarPantsOnFire,

    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.

    I did a little test at Object initializer, it seems works well.

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 31, 2019 5:27 AM