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

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -