2017-08-15 93 views
0

下面的代碼工作如果每行有兩個項目,但它打破了,如果最後一排只有一個項目每兩個項目的排股利。我如何得到這個工作來顯示每1或2個項目的行div?創建使用剃刀

@{ 
    var count = 0; 
    var rowCreate = false; 
} 

if (count == 0 || (count % 2 == 0)) 
{ 
    rowCreate = false; 
    @Html.Raw("<div class='row'>"); 
} 
else { 
    rowCreate = true; 
} 

<div class="col-md-6"> 
    Content 
</div> 

if (rowCreate) { 
    @Html.Raw("</div>"); 
} 

count++; 

回答

0
if (rowCreate) 
       { 
        @Html.Raw("</div>"); 
       } 

       count++; 

       if (CurrentPage.AncestorOrSelf(2).Children.First("Name == \"" + page + "\"").Children.Count() == count && count % 2 != 0) 
       { 
        @Html.Raw("</div>"); 
       }