Answer the question
In order to leave comments, you need to log in
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> }
}
Answer the question
In order to leave comments, you need to log in
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.
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 questionAsk a Question
731 491 924 answers to any question