I have a collection (Generic List) of objects being populated outside the model of a MVC view, and need to show a checkbox for each item in the list.
This works fine for that:
@foreach (Admin_Permission perm in ViewBag.PermissionList)
{
@Html.CheckBox(perm.PermissionKey, new {Value=perm.PermissionID}) @perm.PermissionDesc
<br>
}
That displays the checkboxes one per row... and there are about 50 of them, so it wastes a LOT of space, since each one's description is only about 10 characters or so.
In the past I would use a CheckBoxList with columns set to 5 for this... but that feature seems to be missing with MVC... so I need to figure out a way to do the same thing here somehow. I have played with using a for loop and counting columns and adding etc as we count thru the objects, but it does not seem to take. Always get errors where razor does not like the markeup for closing a TD and starting a new one inside a if statement.
So... the million dollar question is, how the heck do we do this properly in MVC? It seems to me I must be missing something. Its such a stupid problem to have that I must be overlooking something simple. Anyone?
Aucun commentaire:
Enregistrer un commentaire