Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,


In my mvc3 project i have an entity as below
--------------------------------------------

JavaScript
public class Entity
    {
       
        public int iErrorId { get; set; }
       
    }


then using javascript call a function in a controller and pass the

object array as below,
---------------------------------------------------
JavaScript
unction SaveTrackChanges() {

    var _trackChanges = {};

    for (i = 0; i < _drpErrorType.length; i++) {

        _trackChanges["iErrorId"] = document.getElementById(_drpErrorType[i]).options[document.getElementById(_drpErrorType[i]).selectedIndex].value;
        
    }
        
    $.ajax({
        type: "POST",
        url: "../Home/SaveTrackChanges",       
        contentType: "application/json",
        data: JSON.stringify({_trackChanges: _trackChanges}),
        error: function (xhr, textStatus) {
            //            alert(xhr.responseText);
            alert("Error while processing the request, please try again.");
            ShowHideProcessing(0);
        },
        success: function (result, textStatus) {
          

        }
    });
    
}



In controller the function SaveTrackChanges as below :-
--------------------------------------------------
JavaScript
public JsonResult SaveTrackChanges(Entity _trackChanges)
        {
            using (wordscriptEntities dbContext = new wordscriptEntities())
            {
               //
               
                return Json("1");
            }
        }


My doubt is how to iterate through the class property values?

that is, the above code 'iErrorId' as more than one value and pass this value to the controller function.

then, how to loop through this value in 'SaveTrackChanges' function?

Thanks..
Posted
Updated 9-Sep-13 20:23pm
v2

1 solution

 
Share this answer
 
Comments
[no name] 10-Sep-13 5:54am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900