D
D
Dmitry Filandor2015-11-24 21:08:27
HTML
Dmitry Filandor, 2015-11-24 21:08:27

How to display records in a view?

Hello!
Guys tell me how best to display the records. The difficulty is that my markup is not standard
, here is such a representation - joxi.ru/1bmoOv4CX9aMmy that's what comes to mind:

@int Cnt = 0;
 @foreach (var item in ViewBag.Records)
    {        
    //первый ряд из трех записей (и таких рядов будет 4, то есть 12 записей)
  
  if(Cnt == 0) {<div class="row-fluid property-row"> }
  
  if(Cnt < 4)
  {
        
            //первая запись первого ряда
            <div class="span3">
                <article class="property-item">                    
                    <div class="property-attribute">                        
                        <h3 class="attribute-title"><a href="property-single.html">@item.Title</a><i class="icon-heart"></i></h3>                         
                    </div>
                </article>
            </div>   

      //вторая запись первого ряда
            <div class="span3">
                <article class="property-item">                    
                    <div class="property-attribute">                        
                        <h3 class="attribute-title"><a href="property-single.html">@item.Title</a><i class="icon-heart"></i></h3>                         
                    </div>
                </article>
            </div>   
      
      //третья запись первого ряда
            <div class="span3">
                <article class="property-item">                    
                    <div class="property-attribute">                        
                        <h3 class="attribute-title"><a href="property-single.html">@item.Title</a><i class="icon-heart"></i></h3>                         
                    </div>
                </article>
            </div>   
      
       
    Cnt++;
   }		
   
   if(Cnt == 0) { </div>   }
   
   if(Cnt == 4) {<div class="row-fluid property-row"> }
   
   if(Cnt > 3 && <7)
  {
  
   //первая запись второго ряда
            <div class="span3">
                <article class="property-item">                    
                    <div class="property-attribute">                        
                        <h3 class="attribute-title"><a href="property-single.html">@item.Title</a><i class="icon-heart"></i></h3>                         
                    </div>
                </article>
            </div>   

      //вторая запись второго ряда
            <div class="span3">
                <article class="property-item">                    
                    <div class="property-attribute">                        
                        <h3 class="attribute-title"><a href="property-single.html">@item.Title</a><i class="icon-heart"></i></h3>                         
                    </div>
                </article>
            </div>   
      
      //третья запись второго ряда
            <div class="span3">
                <article class="property-item">                    
                    <div class="property-attribute">                        
                        <h3 class="attribute-title"><a href="property-single.html">@item.Title</a><i class="icon-heart"></i></h3>                         
                    </div>
                </article>
            </div>   
  
  }
  
   if(Cnt == 4) { </div>   }
   
  }

but this implementation through a conditional operator is similar to shit code .... so I'm asking for advice from specialists

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
heartdevil, 2015-11-25
@LifeAct

Hello.
You need to make a class with already formatted data (as you need) with a certain structure. Then transfer it to the view, so that everything can be done in one cycle without complex branching inside the whole thing. You can add certain flags to this class in order to indicate in which places you should display certain tags.

D
Dmitry Kovalsky, 2015-11-24
@dmitryKovalskiy

To pass data to View, there is the concept of Model and strongly-typed View. To display data other than lists (i.e., the markup is quite typical, but the data itself is not an array), you can use the "copy-paste" of the markup and substitution of the necessary parameters in the right places.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question