Splitting foreach in a table

无人久伴 提交于 2019-11-28 14:04:27

问题


As of right now my table looks like this:

But I want to split the foreach to have it look something like this

Is possible to do this?

And this is the foreach:

@foreach (var date in ViewBag.MissingDays)
{
  var isoDate = date.ToString("yy-MM-dd");
  <tr>
    <td>
      <a href="javascript:SetDate('@isoDate');">@isoDate</a>
    </td>
  </tr>
}

回答1:


You can use the following code to generate rows containing 9 columns

@{var counter = 1; }
<tr>
  @foreach (var date in ViewBag.MissingDays)
  {
    var isoDate = date.ToString("yy-MM-dd");
    <td><a href="javascript:SetDate('@isoDate');">@isoDate</a></td>
    if (counter % 9 == 0)
    {
      @:</tr><tr> // end current row and begin new one
    }
    counter++;
  }
</tr>


来源:https://stackoverflow.com/questions/31872944/splitting-foreach-in-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!