c# - Store multiple xml node into list and show in MVC view -


i store multiple xml linq result list , show in mvc view stores null value when debugging. anyway store in list? thanks!

my controller:

public actionresult surv_answer_result(int survey_id, string language = "eng") { list<answerquestionviewmodel> viewmodel = new list<answerquestionviewmodel>();              var query = r in db.surv_question_ext_model                         join s in db.surv_question_model                         on r.qext_question_id equals                         s.question_id                         select new { r, s };              var viewmodel = new answerquestionviewmodel();             viewmodel.survey_id = survey_id;              list<string> ansresult = new list<string>();              foreach (var item in query.tolist())             {                  string str = item.s.answer_data;                 xelement qconfig;                 qconfig = xelement.parse(str);                  string value = item.s.question_type;                 int = 0;                  switch (value)                 {                      case "single_line":                         {                                  xelement singlelineans =                                 (from node in qconfig.elements("answer")                                 select node).singleordefault();         unable store=====>    viewmodel.resultanswer = singlelineans.value;                                        ansresult.add(viewmodel.resultanswer[i]);                                 i++;                          }                         break;                      case "multiple_line":                         {                            // nothing                         }                         break;                    viewmodel.add(new answerquestionviewmodel()                 {                                   resultanswer = viewmodel.resultanswer                         });             }              return view(viewmodel);         } } 

my answerquestionmodel:

public string[] resultanswer { get; set; } 

my view:

@model list<surveytool.models.answerquestionviewmodel>     @for(int = 0; < model.count; i++)     {        @html.displayfor(m => m[i].resultanswer[i])     } 

xml answer data sample (will 'ssd' after extract):

<!--question configuration--><answerdata><answer>ssd</answer></answerdata> 

change

      public string[] resultanswer { get; set; } 

to

     public list<string>resultanswer { get; set; }  

and

     viewmodel.resultanswer = singlelineans.value;  

change

     viewmodel.resultanswer = new list<string>();      viewmodel.resultanswer .add(singlelineans.value);  

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -