C# 在多个列上拆分动态列表
我的razor视图中有以下代码,可以动态生成兴趣列表和旁边的勾选框C# 在多个列上拆分动态列表,c#,asp.net-mvc,C#,Asp.net Mvc,我的razor视图中有以下代码,可以动态生成兴趣列表和旁边的勾选框 <div class="form-group"> <div class="col-md-10 col-md-offset-1"> <h3>Tick the areas your club is interested/runs events in</h3> </div> </div> <div class="col-md-offset-
<div class="form-group">
<div class="col-md-10 col-md-offset-1">
<h3>Tick the areas your club is interested/runs events in</h3>
</div>
</div>
<div class="col-md-offset-1">
@for (int i = 0; i < Model.ClubTypeInterests.Count(); i++)
{
<div>
@Html.HiddenFor(x => Model.ClubTypeInterests[i].InterestId)
@Html.CheckBoxFor(x => Model.ClubTypeInterests[i].selected)
@Html.LabelFor(x => Model.ClubTypeInterests[i].ListInterestName, Model.ClubTypeInterests[i].ListInterestName)
</div>
}
</div>
勾选您的俱乐部感兴趣/举办活动的区域
@对于(int i=0;iModel.ClubTypeInterests[i].InterestId)
@Html.CheckBoxFor(x=>Model.ClubTypeInterests[i]。选中)
@LabelFor(x=>Model.ClubTypeInterests[i].ListInterestName,Model.ClubTypeInterests[i].ListInterestName)
}
我想根据列表中的项目数量将其分为2列或3列,而不仅仅是一列。如何实现这一点?为什么不为每次迭代创建一个新列
<div class="col-md-offset-1">
<div class="form-group">
@for (int i = 0; i < Model.ClubTypeInterests.Count(); i++)
{
<div class="col-md-2">
@Html.HiddenFor(x => Model.ClubTypeInterests[i].InterestId)
@Html.CheckBoxFor(x => Model.ClubTypeInterests[i].selected)
@Html.LabelFor(x => Model.ClubTypeInterests[i].ListInterestName,Model.ClubTypeInterests[i].ListInterestName)
</div>
}
</div>
</div>
@对于(int i=0;iModel.ClubTypeInterests[i].InterestId)
@Html.CheckBoxFor(x=>Model.ClubTypeInterests[i]。选中)
@LabelFor(x=>Model.ClubTypeInterests[i].ListInterestName,Model.ClubTypeInterests[i].ListInterestName)
}
因此,将初始div偏移1,然后每个循环迭代使用所需元素创建一个新的div
。
col-md-2
被用作一个例子,将其更改为您需要的内容。如此简单却如此有效,谢谢这正是工作