Splitting foreach in a table

2019-01-29 13:45发布

As of right now my table looks like this:

enter image description here

But I want to split the foreach to have it look something like this enter image description here

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条回答
Viruses.
2楼-- · 2019-01-29 14:07

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>
查看更多
登录 后发表回答