1

in my c# action method

public void ProcessArray(string jsonArray){
//code here

}

The jsonArray parameter receives the string object in the following format:

[{\"studentid\":6968,\"enrolled\":false},{\"studentid\":6970,\"enrolled\":true},{\"studentid\":6972,\"enrolled\":false} ]

but how do i convert the above json string array to C# object array?

update: here is the full signature of the action method:

pubic json ProcessData(int id, int deptid, int teachId, string studentEnrollmentsArr, string userNotes){

}

i dont want to put all the above parameters to a model i want to pass them as paramters.

thanks

Dore.Ad
  • 153
  • 1
  • 10
  • 2
    Create a model with those 2 properties (`int studentid` and `bool enrolled`) and make the method `public ActionResult ProcessArray(IEnumerable jsonArray) { ...` –  Apr 11 '17 at 02:11
  • @StephenMuecke just for curious is it possible to pass jsonArray as a string then internally convert it to a C# object array? – Dore.Ad Apr 11 '17 at 03:56
  • Yes (see the answers in the dupe), but why? The `DefaultModelBinder` will do it for you (assuming you set the `contentType: 'application/json'` header. –  Apr 11 '17 at 04:07
  • @StephenMuecke thanks – Dore.Ad Apr 11 '17 at 04:19
  • @StephenMuecke i think i have given you insufficient informaton the actual signature of the method is pubic json ProcessData(int id, int deptid, int teachId, string studentEnrollmentsArr, string userNotes). i have kept it to short in the original for clarity. as i have updated my OP i don't want to put all these parameters in a model instead i want to keep them separate. reason too many things to edit. So if i want keep them as parameters then how do i convert that json array to C# object array? – Dore.Ad Apr 11 '17 at 05:15

0 Answers0