asp.net mvc - How to bind multiple classes in web api -


$.ajax({      type: "post",     data: "{myevents: " + json.stringify(myevents) + ", myrecurrences: " + json.stringify(myrecurrences) + "}",     url: "/signupadmin/api/signupadminapi/saveevent",     contenttype: "application/json; charset=utf-8",     datatype: "json",     success: function (obj)      {           alert("success");      },      error: function (obj)      {           alert(obj.error());      }       });     [httppost]     public bool saveevent(evancedeventdata myevents,recurrencedata myrecurrences)     {         return true;     } 

i have used 2 class files(evancedeventdata , recurrencedata) mentioned , trying bind json objects 2 classes ajax throws error "cannot bind multiple parameters" can 1 suggest reason why not getting binded

would better support questions examples of data, such json string you're posting , exception report.

however, try creating wrapper class encapsulate myevents , myrecurrences, like:

public class mywrapperclass {   evancedeventdata myevents {get;set;}   recurrencedata myrecurrences {get;set;} } 

then change post action expect wrapper class:

[httppost] public bool saveevent(mywrapperclass data) {     return true; } 

then should able read data this:

[httppost] public bool saveevent(mywrapperclass data) {     var events = data.myevents     //do stuff events      var recurrences = data.myrecurrences     //do stuff recurrences      return true; } 

(above example - no need create , use separate variables access data).

hope helps.

ben


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -