【发布时间】:2021-12-10 04:35:48
【问题描述】:
您好,我有这张表,我想在其中显示来自控制器的组数据,它返回按会议 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 的经验,我尝试在网上寻找解决方案,但到目前为止没有任何效果,我该如何解决这个问题?谢谢
【问题讨论】:
标签: c# sql asp.net-mvc linq