实体框架 MVC 中的分组
大家好,我目前已经使用以下方式输出了电话号码列表:-
控制器:-
public ActionResult ViewSubRange(int id)
{
IEnumerable<Number> numbers = context.Numbers.Where(m => m.RangeID == id).ToList();
return View("SubRange", numbers);
}
视图:-
@model IEnumerable<TelephoneNumberManagement.Models.Number>
<table>
<tr>
<th>
Number
</th>
<th>
Status
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.Number1</td>
<td>@item.Status.StatusName</td>
</tr>
}
</table>
这很好,但是我注意到我们可以输出很多号码。我想知道是否可以对数字进行分组,例如按客户分组。所以我想要实现的是:-
01132210000-01132210999 客户A
01132211000-01132211009 客户B
01132211010-01132211029 客户 C
Hi all i've currently got a list of telephone numbers being output using:-
Controller:-
public ActionResult ViewSubRange(int id)
{
IEnumerable<Number> numbers = context.Numbers.Where(m => m.RangeID == id).ToList();
return View("SubRange", numbers);
}
View:-
@model IEnumerable<TelephoneNumberManagement.Models.Number>
<table>
<tr>
<th>
Number
</th>
<th>
Status
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.Number1</td>
<td>@item.Status.StatusName</td>
</tr>
}
</table>
This is fine, however i've noticed that we can have a lot of numbers being output. I was wondering if its possible to group the numbers, so for example by Customer. So what i want to achieve is something like:-
01132210000-01132210999 CUSTOMER A
01132211000-01132211009 CUSTOMER B
01132211010-01132211029 CUSTOMER C
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以定义一个新的视图模型:
然后按客户名称分组:
最后在您的视图中:
You could define a new view model:
and then group by customer name:
and finally in your view: