json - how to send complex type from client side to server side -
i have page needs send complex data client side webmethod in asp.net mvc. data :
{"tbl":[{"row":{"items":[{"name":"madrak1","val":"fdsfds"},{"name":"mahaletahsil1","val":"fdsfds"},{"name":"reshte1","val":""},{"name":"start1","val":""},{"name":"end1","val":""}]}}]}
i need have class named table put variables inside it. webmethod :
public actionresult savedetailedinfo(list<rrow> tbl) { return json(new { status = "success", message = "success" }); }
your c# classes should like:
public class item { [jsonproperty("name")] public string name { get; set; } [jsonproperty("val")] public string val { get; set; } } public class row { [jsonproperty("items")] public ilist<item> items { get; set; } } public class tbl { [jsonproperty("row")] public row row { get; set; } } public class table { [jsonproperty("tbl")] public ilist<tbl> tbl { get; set; } }
and mvc method:
public actionresult savedetailedinfo(table table) { return json(new { status = "success", message = "success" }); }
so sending data front end...
var table = { "tbl": [{ "row": { "items": [{ "name": "madrak1", "val": "fdsfds" }, { "name": "mahaletahsil1", "val": "fdsfds" }, { "name": "reshte1", "val": "" }, { "name": "start1", "val": "" }, { "name": "end1", "val": "" }] } }] }; var xhr = new xmlhttprequest(); xhr.open('post', '/home/savedetailedinfo', true); xhr.setrequestheader('content-type', 'application/json; charset=utf-8'); // send collected data json xhr.send(json.stringify(table));
should result in...
Comments
Post a Comment