Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在多个列上拆分动态列表_C#_Asp.net Mvc - Fatal编程技术网

C# 在多个列上拆分动态列表

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-

我的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-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
被用作一个例子,将其更改为您需要的内容。

如此简单却如此有效,谢谢这正是工作