c# - Pulling single elements for headers from a List Model -


i have list model several rows. in model, pull out parts display in top of page, titles data , data parts itself. when pull list or ienumeration view display data expected, not able display first() or other way of getting these headers out. should go view display way?

goal:
header row event name , date (currently in each row of list) groups or tables of data own headers based on data in list data detail per group above.

i have partial view loop through core data..

advice please?

code messy, here is:

view

@model ienumerable<emanager.web2.models.eventclasscomplistvm>  @{     viewbag.title = "eventcompclassreport"; }  <h2>eventcompclassreport</h2>   <table class="table">      @html.displayfor(model => model.eventname) //tried several ways identify this, in list no way single out.           @html.editorformodel()  }  </table> 

partial view (works expected looping through list)

@model emanager.web2.models.eventclasscomplistvm <tr>     <td>         @html.displayfor(modelitem => model.comp_eventid)     </td>     <td>         @html.displayfor(modelitem => model.compname)     </td>     <td>         @html.displayfor(modelitem => model.classname)     </td>     <td>         @html.displayfor(modelitem => model.classorder)     </td>     <td>         @html.displayfor(modelitem => model.iscrossover)     </td> </tr>     

controller class (although returning several rows of data)

 public actionresult buildeventclassreports()         {             var model = o in _db.events                            join o2 in _db.event_classes on o.eventid equals o2.eventid                            o.eventid.equals(o2.eventid)                            join o3 in _db.event_class_compeditors_s on o2.eventclassid equals o3.eventclassid                            o2.eventclassid.equals(o3.eventclassid)                            join o4 in _db.compeditors on o3.compeditorid equals o4.compeditorid                            o3.compeditorid.equals(o4.compeditorid)                            join o5 in _db.class_definitions on o2.classid equals o5.class_definition_id                            o2.classid.equals(o5.class_definition_id)                            o.currentevent.equals(true)                            orderby o2.classorder                            //orderby o3.comp_eventid                             select new eventclasscomplistvm {                                                              eventname = o.eventname,                                                             eventdate = o.date_end,                                                             classname = o5.class_name,                                                             comp_eventid = o3.comp_eventid,                                                             classorder = o2.classorder,                                                             compname = (o4.firstname + " " + o4.lastname),                                                             iscrossover = o3.iscrossover };              return view(model); 

edit:

some new code has gotten me closer.. cannot see how few data parts out of first foreach. line of code @html.display not working.. text "mumbo jumbo" works great , splits groups. appreciated.!!

current view code:

   <h2>         @(model.any() ? model.first().eventname : "")         @(model.any() ? model.first().eventdate.toshortdatestring() : "")      </h2>          @foreach (var group in model.groupby(item => item.classid))                 {                         <tr><td><b>mumbo jumbo</b>                             </td></tr>             @html.displayfor(modelitem => model.classname) //cannot line work.                       foreach (var item in group)                     {                         <tr>                             <td>                                 @html.displayfor(modelitem => item.comp_eventid)                             </td>                             <td>                                 @html.displayfor(modelitem => item.compname)                             </td>                             <td>                                 @html.displayfor(modelitem => item.classname)                             </td>                             <td>                                 @html.displayfor(modelitem => item.classorder)                             </td>                             <td>                                 @html.displayfor(modelitem => item.iscrossover)                             </td>                         </tr>                      }                  } 

i'm sure there's better way this, can think of right store titles separate list.

create new class model view , include list of titles data. e.g.

public class mainviewmodel {     public ienumerable<string> titles { get; set;}     public ienumerable<emanager.web2.models.eventclasscomplistvm> models { get; set;} } 

populate class accordingly in buildeventclassreports() action, , pass class view.

you can pass model.eventclasscomplistvm partial view using @html.partial("viewname", model.eventclasscomplistvm)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -