【问题标题】:How to split items into columns (MVC3)如何将项目拆分为列(MVC3)
【发布时间】:2012-05-18 09:40:43
【问题描述】:

我不知道如何将项目拆分为 N 列。 IE。分成 3 列。怎么可能做到? (不,我只是垂直地做所有事情)

谢谢你的任何线索!!!

foreach (var answer in @question.Answers)
{
   @Html.CheckBox("answer_CheckBox_" + answer.ID.ToString(), false, new { @id = answer.ID });  
   <label style="margin-left: 0.5em;">@answer.Title</label>
   <br />                                                                                                         
}

【问题讨论】:

    标签: c# .net asp.net-mvc-3


    【解决方案1】:

    使用模运算符将答案分成可被 3 整除的组:

    int i = 1; 
    @foreach (var answer in @question.Answers) {
       @Html.CheckBox("answer_CheckBox_" + answer.ID.ToString(), false, new { @id = answer.ID });  
       <label style="margin-left: 0.5em;">@answer.Title</label>
    
       i % 3 == 0 ? <br/> : ""
       i++
    }
    

    注意 - 如果我的剃刀语法不正确,请原谅...

    【讨论】:

    • 谢谢@Xander!您节省了我的时间,感谢您的回答!
    猜你喜欢
    • 2020-08-16
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多