c# - 如何在html表asp.net mvc中显示组数据
问题描述
嗨,我有这张表,我想在其中显示来自控制器的组数据,它返回按会议 ID 分组的对象
var res = db.MinuteofMeet.GroupBy(x => x.MeetID).ToList();
看法
{
int i = 1;
foreach (var item in Model)
{
DatContext dbs = new DatContext();
<tr>
<td hidden>
@Html.DisplayFor(modelItem => item.MeetID)
</td>
<td>
@Convert.ToString(string.Format("{0:dd-MM-yyyy}", item.CDate))
</td>
<td>
@Html.DisplayFor(modelItem => item.SubjectDetail)
</td>
<td>
@Convert.ToString(string.Format("{0:dd-MM-yyyy}", item.Meetdate))
</td>
<td>
@*@Html.DisplayFor(modelItem => item.ReviewedBy)*@
Demo
</td>
<td>
@Html.DisplayFor(modelItem => item.responsible)
</td>
<td hidden> @Html.DisplayFor(modelItem => item.action_type)</td>
<td>
<img data-id="@item.Comment" data-toggle="modal" data-target="#commentsmodal" class="datimage" src="~/MatAssets/images/plus.png">
</td>
但是当我运行应用程序时,它会抛出一个错误说
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[System.Linq.IGrouping`2[System.Int32,SmartBookingPro.Models.MinuteOfMeeting]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[SmartBookingPro.Models.MinuteOfMeeting]'.
这是我的模态
{
[Table("tbl_minofmeet")]
public class MinuteOfMeeting
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public int MeetID { get; set; }
public string RoomName { get; set; }
//public string Client { get; set; }
//public string Subject { get; set; }
public string Minutes { get; set; }
public string Comment { get; set; }
public string ReviewedBy { get; set; }
public DateTime? CDate { get; set; }
public string UserID { get; set; }
public string Minstatus { get; set; }
public string Task_status { get; set; }
public DateTime? Meetdate { get; set; }
public string responsible { get; set; }
public string action_type { get; set; }
public string SubjectDetail { get; set; }
我以前没有使用 SQL groupdata 的经验,我尝试在线寻找解决方案,但到目前为止没有任何效果,我该如何解决这个问题?谢谢
解决方案
你的模型应该是@model IEnumerable<IGrouping<int, MinuteOfMeeting>>
- var res = db.MinuteofMeet.GroupBy(x => x.MeetID) 而不是 ToList()
推荐阅读
- ios - 旧设备上的 MTKView 与 GLKView 性能
- django - 如何在 Django 中正确编写#hashtag 的 url
- vuejs2 - How to put just a value from a radio input into an array in Vuejs and Vuex
- android - 使用 ssl pinning 时如何防止嗅探?
- android - 允许多个用户在 1 个帐户上同时登录
- sql - 如何从两个表中提取列中不相关的数据。?
- swiftui - SwiftUI:从 NavigationView 打开 CNContactViewController?
- cassandra - PreparedStatement 应该在单例类中准备一次,然后在 DAO 实现中引用
- wordpress - 带有 wordpress 的 EC2 - 每天空间不足(设备上没有剩余空间) - 无法启动 apache
- python - 在 Google 的 Quickdraw 数据集上应用机器学习算法