How to get value from jquery each loop when controller returns list

jquery each json array
jquery foreach array
jquery each break
jquery each continue
jquery each div
how to iterate list using jquery
jquery array of objects
foreach loop in ajax success: function

I have list and return from controller and i'm trying to show in a mvc view using jquery each loop function.I can get to list and send to view but when jquery loop start i cannot get index and value.I checked Console and Sources,values are there.

This is my controller codes

  public JsonResult electric()

        int id = Convert.ToInt32(Session["id"]);
        string cs = "data source=LNPC;initial catalog=db;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework";
        SqlConnection connection = new SqlConnection(cs);

        SqlCommand command = new SqlCommand("electrcic_bills", connection);
        command.CommandType = System.Data.CommandType.StoredProcedure;
        command.Parameters.AddWithValue("@id", id);
        SqlDataReader reader = command.ExecuteReader();

        List<analiz> TestList = new List<analiz>();
         analiz electric;

        while (reader.Read())
            electric= new analiz();
            electric.jan= Convert.ToDouble(reader["jan"].ToString());
            electric.feb= Convert.ToDouble(reader["feb"].ToString());
            electric.march= Convert.ToDouble(reader["march"].ToString());
            electric.april = Convert.ToDouble(reader["april"].ToString());


        return Json(new { List = TestList }, JsonRequestBehavior.AllowGet);

Jquery codes

           $("#electric").click(function () {

           $("#canvas1").append('<canvas id="myCharts" width="200" height="200"></canvas>');
               type: "GET",
               url: "/MainController/electric",

               dataType: "json",
               success: function (List) {

                   var data = List.List;
                   $.each(data, function (index, value) {


With this method i cannot get value but when i write electric.push(List.List[0].jan._bills_electric) like this i can get value manualy perfctly.

This my Source codes from browser

Local List:List: Array(1) 0: jan_bills: null jan_bills_electric: 135 dec_bills: null dec_bills_electric: 60

You are using List word in your return Json() statement. This may be ambiguous for Java. Try using another name with camel case typography to solve the problem.

jQuery foreach: Using jQuery $.each, Learn how to loop through elements, arrays and objects with jQuery jQuery's foreach equivalent can be very useful for many situations. These examples will get you started and teach you how you can loop The ability to be able to loop through elements in a list can be very useful for all kinds of tasks. Solution : Convert Java List to JSON. The solution is converts the Java List into JSON format before pass it to jQuery. In Spring controller, use Jackson (or other JSON processors)to convert the List into JSON format.

In your Javascript, try to use

var data = List["List"];

instead of

var data = List.List;

jQuery.each(), The $.each() function can be used to iterate over any collection, whether it is an If an object is used as the collection, the callback is passed a key-value pair $.​each() loop at a particular iteration by making the callback function return false . When the first element in the collection is a select-multiple (i.e., a select element with the multiple attribute set), .val() returns an array containing the value of each selected option. As of jQuery 3.0, if no options are selected, it returns an empty array; prior to jQuery 3.0, it returns null.

Okey i found my answer and where l am wrong. First- there is nothing wrong in my controller Second- in each loop function,my array not only array,it is array in OBJECT.I've found this link and try each loop in a each loop and i got my items from jquery loop.

var json = [ 
 { 'red': '#f00' },
 { 'green': '#0f0' },
 { 'blue': '#00f' }

$.each(json, function () {
   $.each(this, function (name, value) {
      console.log(name + '=' + value);

Iterating on a list of objects from javascript, From my controller in mvc 4, I request a collection of objects from my success: function (data) { //Use a jQuery each loop to iterate through Trigger the AJAX call --> <input type="button" onclick="recollectData()" value="Grab Data" /> "​Description of C" }); //Return your JSON object return Json(objects); }. I have list and return from controller and i'm trying to show in a mvc view using jquery each loop function.I can get to list and send to view but when jquery loop start i cannot get index and valu

Posting Array with JQuery to MVC Controller, I'm trying to post an array using jQuery and ajax to a MVC controller, but am The code executes up until the foreach loop. model.SocialAssessments returns a count of 0. When I approach the problem like you illustrated, the list doesn't seem to have any records, therefore nothing to loop through to write  Just use the Json () method of the Controller class to serialize your C# object to JSON and return it as an ActionResult. You can use jQuery to wire up the AJAX and call the controller method via HTTP GET or POST using $.get () and $.post () respectively.

Store HTML Table Values in a Javascript Array and Send to a PHP , The following jQuery code can be used to read each cell value in the above table​. The jQuery .each function is used to iterate through the table rows TableData.shift(); // first row will be empty - so remove return TableData; }. The Selected Value of DropDownList is easily available using Model or using Request.Form collection, but in order to get the Selected Text, the Selected Text is copied to a Hidden Field using jQuery and then it is fetched inside Controller in ASP.Net MVC Razor. TAGs: ASP.Net, HTML, DropDownList, MVC

How to get all selected checkboxes in an array using jQuery , In case of return value, This method returns the value attribute's value of the then calls the .each() method to each element and finally push them into the array​. Notice: In the above code I use the jQuery each this object to refer the current element and get it’s values. The jQuery each method can be also used to iterate over arrays, objects and array like objects. In this case, the object to loop over, is given as the first argument, like shown below: $.each(object, function (index, value){ //code });

  • that didn't work too loop doesnt work when data comes