asp.net mvc - How to write the Looping structure for Parent-Child relationships? -


i using treetable.js. procedure saved child id , parent id. insert data inserted. return data may show in table or grouping error. use igrouping object convertion error. please tell me child parent loop structure below.

in model:

public string name {get;set;}     public int childid {get;set;} public int  parentid {get;set;} 

in controller:

var list = db.table.groupby(s=>s.parentid).tolist();    return view(list); 

in view:

 <table id="example-basic">          <tr>               <th>name</th>              <th>data id</th>              <th>parent id</th>          </tr>      @foreach (var item in model)      {         <tr data-tt-id='@item.dataid' data-tt-parent-id='@item.dataparentid'>              <td>@item.name</td>             <td>@item.dataid</td>             <td>@item.dataparentid</td>         </tr>      }  </table> 

if want rid of exception grouping should write this:

  var list = db.table.groupby(s => s.parentid).select(x => new chartofaccount    {         parentid = x.key,        childid = x.first().childid,        name = x.first().name   }).tolist();   return view(list); 

as can see 1 row each parentid becouse or grouping.

but gess searching else.


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 -