asp.net mvc - How to assign string data to viewmodel in mvc? -
this code
public class studentviewmodel { public list<student> studentid{get;set;} } public calss student { public list<string> marks {get;set;} public string id{get;set;} public string name{get;set;} }
i have string data like
[{"id":"101","name":"abc","marks":[["67","34"]]},{"id":"102","name":"xyz","marks":[["98"],["85]]}]
in above student view model contains list class student. have number of student details. how assign above string data view model in mvc controller.
you need parse string data c# object using json parser e.g. newton soft , convert c# object.
var student = jsonconvert.deserializeobject<list<student>>(strinput);
or can use system.web.script.serialization.javascriptserializer
, code follows
var students= new javascriptserializer().deserialize<list<student>>(strinput);
Comments
Post a Comment