Foreach loop for tables in MVC4

前端 未结 2 1061
南笙
南笙 2021-01-15 23:12

I am doing my project in MVC4 using c#. I have an IEnumerable list in my model. I use the following loop to list that in my view.

       
2条回答
  •  别那么骄傲
    2021-01-15 23:38

    Firstly it is entirely possible to do this. Secondly, you should not do this. Consider using

    to make the layout "flow". The "table" created with divs will resize with the window then.

           @{
               int groupings = 3;
               var grouped = Model.Select((x,i) => new { x, i = i / groupings  })
                             .GroupBy(x => x.i, x => x.x);
           }
    
           
@foreach(var items in grouped) { @foreach(var item in items) { } }
Rtn. @item.Mem_NA
(@item.Mem_Occ)

Using divs you would...

    @foreach(var item in Model)
     {
         
Rtn. @item.Mem_NA
(@item.Mem_Occ)
}

提交回复
热议问题