Trying to organise a display form using .net MVC and bootstrap - however, getting some odd bootstrap wrapping behavior.
I have the following code;
@for (int i = 0; i < Model.People.Count(); i++)
{
var person = Model.People[i];
<label class="col-md-3 col-form-label">@Html.DisplayNameFor(modelItem => person.Name) @(i + 1)</label>
<div class="col-md-3">
@Html.DisplayFor(modelItem => person.Name, new { @class = "form-control" })
</div>
}
What I'm expecting is a layout kinda like this:
<table>
<tr>
<td>Person 1:</td>
<td>Joe</td>
<td>Person 2:</td>
<td>Fred</td>
</tr>
<tr>
<td>Person 3:</td>
<td>Sally</td>
<td>Person 4:</td>
<td>etc</td>
</tr>
But what im actually getting is like this:
<table>
<tr>
<td>Person 1:</td>
<td>Joe</td>
<td>Person 2:</td>
<td>Fred</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>Person 3:</td>
</tr>
<tr>
<td>Sally</td>
<td>Person 4:</td>
<td>etc</td>
</tr>
</table>
I was under the impression that the bootstrap grid layout was simply supposed to wrap if it exceeds 12. So 4x col-md-6 would essentially produce 2 rows which both have 2 columns at 50%.
Can anyone offer any insight on why the wrapping behavior is acting strangely if the elements are an alternating label / div? Possibly a bug with bootstrap - considering their own documentation uses the same kind of markup (e.g.)?
Was going to say:
Would changing the markup to have an extra div be my best approach? e.g.
<div class="col-md-3">
<label>Person 1:</label>
</div>
<div class="col-md-3>Joe</div>
But as it turns out - this also has the strange wrapping behaviour: here