将多个“”合并到一个“ ”中。 ASP.NET MVC3
我有一个 ASP.NET MVC3 项目。
我想在一个表 中插入一些
。这些
各包含一个
。这些来自位于partialView中的switch(),并渲染到另一个视图中(其中
可以包含多个
) 。这是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;
}
}
这个partialView 在这里渲染:
<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>
当 switch() 多次转到相同的情况时,会出现问题。如果我的 PitlaneId 按以下顺序排列:1,2,2,3;它将在我的表中创建 4 个 。在这种情况下,我应该只有 3 个
,并且具有相同 PitlaneId=2 的两个
应该位于同一个
。 我的意思是
具有相同 id 的应该合并在一起。当 PitlaneId 按以下顺序出现时情况相同:1,2,3,2。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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我让它发挥作用的唯一方法。它看起来很臭,但它提供了您指定的元素的顺序。
This is the only way I could make it work. It seems smelly, but it provides the order of elements you specified.