my model: public class Hello { public List<string> name; public List<string> phone; public List<string> contact; } my controller code is public ActionResult Home(Hello obj) // obj is coming out to be null { } my script is var names =[]; var phones =[]; var contacts = []; // some code to fill the arrays var obj = JSON.stringify({ name: names, phone: phones, contact: contacts, }); debugger; $.ajax({ cache: false, url: 'Home', data: { obj:obj }, success: function (data) { var response = JSON.parse(data); window.location = 'Download?fileGuid=' + response.FileGuid + '&filename=' + response.FileName; } })
public ActionResult Home(string obj) { JavaScriptSerializer js = new JavaScriptSerializer(); Hello objHello = js.Deserialize<Hello>(obj); }
using System.Web.Script.Serialization
JSON.stringify
var obj = { name: names, phone: phones, contact: contacts, }); $.ajax({ cache: false, url: 'Home', data: JSON.stringify({ obj:obj }), ...
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)