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...

enter image description here

ps. there easy way convert json objects c# classes


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -