I have an ASP.NET MVC3 project.
I want to insert some <td>
's in one table <tr>
. These <td>
's contain one <div>
each. These comes from a switch() which is in a partialView and renders into another View (where is the <tr>
which could contain multiple <td>
's).
This is the partialView:
@foreach (var item in Model)
{
switch (item.PitlaneId)
{
case 1:
<td id=a>
<div class="drag">
Name: @Html.DisplayFor(modelItem => item.Name) <br />
Constrainted: @Html.DisplayFor(modelItem => item.Constrainted) <br />
</div>
</td>
break;
case 2:
<td id=b>
<div class="drag">
Name: @Html.DisplayFor(modelItem => item.Name) <br />
Constrainted: @Html.DisplayFor(modelItem => item.Constrainted) <br />
</div>
</td>
break;
case 3:
<td id=c>
<div class="drag">
Name: @Html.DisplayFor(modelItem => item.Name) <br />
Constrainted: @Html.DisplayFor(modelItem => item.Constrainted) <br />
</div>
</td>
break;
default: break;
}
}
And this partialView renders here:
<table title="test" id="testTableID">
<colgroup> @foreach (var item in Model){<col width="300" />} </colgroup>
<tbody>
<tr>
@{Html.RenderAction("Tasks"); } @* <--- Here it renders*@
</tr>
</tbody>
</table>
The PROBLEM appears when switch() goes to the same case multiple times. If I have PitlaneId in this order: 1,2,2,3; It will create 4 <td>
's in my table. In this case I should have only 3 <td>
's and the two <div>
's with the same PitlaneId=2 should be inside the same <td>
. I mean <td>
's with the same id should merge together. Same situation when PitlaneId comes in this order: 1,2,3,2.