c# - Show XML node value in MVC view by number of similar node? -


is there anyway group xml node value similar number? had tried output value below can't out want. please guide me on this. thanks!

my answer_data sample in database: (after extract c1 , c2)

question_id |  answer_data ==============================================     1       | <answer_data><answer>c1</answer>     2       | <answer_data><answer>c2</answer>     3       | <answer_data><answer>c2</answer> 

string[] data after extract using linq:

["c1","c2","c2"] 

able view in mvc:

c1 c2 c2 

what want is:

c1 - 1 c2 - 2 

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;                      string[] resultanswer = new string[queryresult.count()];                      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 "choices":                                 {                                     xelement choicestype =                                     (from node in qconfig.elements("choicestype")                                      select node).singleordefault();                                      viewmodel.choicetype = choicestype.value;                                      xelement choicesans = here answer data ===>> (from node in qconfig.elements("answer")                                     select node).singleordefault();                                      resultanswer[i++] = choicesans.value;                                     viewmodel.resultanswer = resultanswer;                                  }                                 break;                              case "multiple_line":                                 {                                    // nothing                                 }                                 break;                            viewmodel.add(new answerquestionviewmodel()                         {                                           resultanswer = viewmodel.resultanswer                                 });                     }                      return view(viewmodel);                 }         } 

my view:

 if (model[i].choicetype == "singlechoice")                {                 (int x = 0; x < model[i].resultanswer.count(); x++)                 {                 @html.labelfor(m => m[i].answer, model[i].resultanswer[x].tostring(),new{ @class="qlabel2" })                  <br/>             }        } 

as stating in question receiving array of element try group

string[] strarray = new string[] {"c1","c2","c2"}; var groups = str in strarray               group str str g              select new {                key = g.key,                count = g.count()              } 

try group using linq

var xmlstr="<root><answer_data><answer>c1</answer></answer_data> <answer_data><answer>c2</answer></answer_data> <answer_data><answer>c2</answer></answer_data></root>";  xdocument xmldoc = xdocument.parse(xmlstr);  var groups = record in xmldoc.descendants("answer_data")              group record (string)record.element("answer")                g              select new {                key = g.key,                count = g.count()              } 

Comments

Popular posts from this blog

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

linux - disk space limitation when creating war file -

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