Abhilash J A

Abhilash J A

  • NA
  • 2.4k
  • 582.3k

Recursive Parent Child hierarchy with checkbox MVC 5

Feb 23 2017 6:58 AM
Hello everyone,
 
I want to bind Html like recursive Parent Child hierarchy with checkbox.
 
 
I have tried by foreach loop but showing only one productcategoryname.
  1. @model List<Rebox.BIL.DataModel.ProductCategoryDM>  
  2. @{  
  3. Layout = "~/Views/Shared/_Layout.cshtml";  
  4. }  
  5. <!DOCTYPE html>  
  6. <html>  
  7. <body>  
  8. <div class="board-canvas m-t-20">    
  9.                     @foreach (var item in Model)    
  10.                     {    
  11.                             if (item.idParentCategoryProduct == 0)    
  12.                             {    
  13.                                 <div id="board" class="u-fancy-scrollbar js-no-higher-edits js-list-sortable ui-sortable">    
  14.                                     <div class="js-list list-wrapper list-padding u-fancy-scrollbar">    
  15.                                         <ul class="offered-list">    
  16.                                             <li>    
  17.                                                 <div class="checkbox ">    
  18.                                                     <label class="hd-txt"><input type="checkbox" value="">@item.ProductCategoryName</label>    
  19.                                                 </div>    
  20.                                             </li>    
  21.                                             @if (item.idParentCategoryProduct != 0)    
  22.                                             {    
  23.                                                 <li>    
  24.                                                     <div class="checkbox ">    
  25.                                                         <label><input type="checkbox" value="">@item.ProductCategoryName</label>    
  26.                                                     </div>    
  27.                                                     @Html.Partial("_productOffered", item)    
  28.                                                 </li>    
  29.                                             }    
  30.                                         </ul>    
  31.                                     </div>    
  32.                                 </div>    
  33.                             }                            
  34.                     }    
  35.                 </div>   
  36. </body>  
  37. </html> 
It is the child partial view page,
  1. @model Rebox.BIL.DataModel.ProductCategoryDM  
  2. @{  
  3.   
  4. }  
  5. @foreach (var item in Model.productCategory)  
  6. {  
  7.     <ul class="offered-sub-list">  
  8.         @if (item != null)  
  9.         {  
  10.             <li>  
  11.                 <div class="checkbox ">  
  12.                     <label><input type="checkbox" value="">@item.ProductCategoryName</label>  
  13.                     @if (item.productCategory.Count > 0)  
  14.                     {  
  15.                         @Html.Partial("_productOffered", item)  
  16.                     }  
  17.                 </div>  
  18.             </li>  
  19.         }  
  20.     </ul>  

And this table structure. I want to show 0 idparentcategoryproduct name at top heading by each seperated coloums like above image showing.
 
 
 
How can I manage foreach loop at View page?
 
Please help me...
 

 

Answers (3)