asp.net mvc - Passing array to MVC controller via jQuery -


trying pass list of objects mvc controller jquery script. controller ain't getting list. ideas?

script

function refreshxerodata(obj, planid, date, list) {     // list comes in serialized array     // list = "[{"id":245225,"xerofromdate":"4/22/2015 12:00:00 am","xerotodate":""},{"id":245226,"xerofromdate":"4/1/2016 12:00:00 am","xerotodate":"4/30/2016 12:00:00 am"}]"      var model = { planid: planid, date: date, list: list };      $.ajax({         type: 'post',         url: url,         data: model,         success: function (data) {             // code removed clarity         },      });  } 

controller

public jsonresult refresh(int planid, datetime date, list<xeroscenariomodel> list) {     // list null     // code removed clarity } 

model

public class xeroscenariomodel {     public int id { get; set; }     public string xerofromdate { get; set; }     public string xerotodate { get; set; } } 

i went through code try code mentioned below.

<script type="text/javascript"> function refreshxerodata() {     // list comes in serialized array     var planid = 1234;     var date = new date();     list = '[{"id":245225,"xerofromdate":"4/22/2015 12:00:00 am","xerotodate":"4/30/2016 12:00:00 am"},{"id":245226,"xerofromdate":"4/1/2016 12:00:00 am","xerotodate":"4/30/2016 12:00:00 am"}]';      var model = { planid: planid, date: "4/30/2016 12:00:00 am", list: json.parse(list) };      $.ajax({         type: 'post',         url: '../../sample/refresh',         data: json.stringify(model),         contenttype: "application/json",         success: function (data) {             // code removed clarity         },      }); } 


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -