I use ASP.NET MVC and bootstrap. I have many objects (>2) in collection and for each need a <div class="col-xs-6">
but with only 2 cols in a row. How to achive this using loop?
There is 1 way but I am looking for something better:
@model List<Object>
@using (Html.BeginForm("ActionName", "ControllerName"))
{
<div class="row">
@for (int i = 0; i < Model.Count; i++)
{
if (i % 2 != 0) {
<div class="row">
<div class="col-xs-6">
@Html.TextBoxFor(o => o[i].Value)
</div>
</div>
} else {
<div class="col-xs-6">
@Html.TextBoxFor(o => o[i].Value)
</div>
}
}
</div>
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…