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











up vote
1
down vote

favorite












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);
connection.Open();
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());
TestList.Add(electric);

}

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


Jquery codes



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

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

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

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

},
});
});


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










share|improve this question


























    up vote
    1
    down vote

    favorite












    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);
    connection.Open();
    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());
    TestList.Add(electric);

    }

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


    Jquery codes



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

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

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

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

    },
    });
    });


    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










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      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);
      connection.Open();
      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());
      TestList.Add(electric);

      }

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


      Jquery codes



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

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

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

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

      },
      });
      });


      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










      share|improve this question













      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);
      connection.Open();
      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());
      TestList.Add(electric);

      }

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


      Jquery codes



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

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

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

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

      },
      });
      });


      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







      java jquery ajax model-view-controller






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 17:55









      omer1596

      156




      156
























          3 Answers
          3






          active

          oldest

          votes

















          up vote
          0
          down vote













          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.






          share|improve this answer





















          • that didn't work
            – omer1596
            Nov 10 at 18:51


















          up vote
          0
          down vote













          In your Javascript, try to use



          var data = List["List"];


          instead of



          var data = List.List;





          share|improve this answer





















          • that didn't work too loop doesnt work when data comes
            – omer1596
            Nov 10 at 19:41


















          up vote
          0
          down vote













          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);
          });
          });








          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241832%2fhow-to-get-value-from-jquery-each-loop-when-controller-returns-list%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            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.






            share|improve this answer





















            • that didn't work
              – omer1596
              Nov 10 at 18:51















            up vote
            0
            down vote













            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.






            share|improve this answer





















            • that didn't work
              – omer1596
              Nov 10 at 18:51













            up vote
            0
            down vote










            up vote
            0
            down vote









            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.






            share|improve this answer












            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.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 at 18:05









            Majid

            7,72285498




            7,72285498












            • that didn't work
              – omer1596
              Nov 10 at 18:51


















            • that didn't work
              – omer1596
              Nov 10 at 18:51
















            that didn't work
            – omer1596
            Nov 10 at 18:51




            that didn't work
            – omer1596
            Nov 10 at 18:51












            up vote
            0
            down vote













            In your Javascript, try to use



            var data = List["List"];


            instead of



            var data = List.List;





            share|improve this answer





















            • that didn't work too loop doesnt work when data comes
              – omer1596
              Nov 10 at 19:41















            up vote
            0
            down vote













            In your Javascript, try to use



            var data = List["List"];


            instead of



            var data = List.List;





            share|improve this answer





















            • that didn't work too loop doesnt work when data comes
              – omer1596
              Nov 10 at 19:41













            up vote
            0
            down vote










            up vote
            0
            down vote









            In your Javascript, try to use



            var data = List["List"];


            instead of



            var data = List.List;





            share|improve this answer












            In your Javascript, try to use



            var data = List["List"];


            instead of



            var data = List.List;






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 at 18:58









            Majid

            7,72285498




            7,72285498












            • that didn't work too loop doesnt work when data comes
              – omer1596
              Nov 10 at 19:41


















            • that didn't work too loop doesnt work when data comes
              – omer1596
              Nov 10 at 19:41
















            that didn't work too loop doesnt work when data comes
            – omer1596
            Nov 10 at 19:41




            that didn't work too loop doesnt work when data comes
            – omer1596
            Nov 10 at 19:41










            up vote
            0
            down vote













            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);
            });
            });








            share|improve this answer

























              up vote
              0
              down vote













              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);
              });
              });








              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                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);
                });
                });








                share|improve this answer












                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);
                });
                });








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

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





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

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






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 9:37









                omer1596

                156




                156






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241832%2fhow-to-get-value-from-jquery-each-loop-when-controller-returns-list%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine