嗨,我有这个表,我想从控制器显示组数据,它返回按会议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
- var res = db.MinuteofMeet。GroupBy (x =比;x.MeetID)代替ToList()
如果你删除。groupby (x =>x.MeetID)它将是会议纪要列表
现在你的变量很可能是List
在GroupBy之后,你可以/应该这样选择:.Select(妈妈=比;new MintuesOfMeetingModel {MeetId = mom.FirstOrDefault()}).ToList()
你可能需要创建一个新的模型来实现这个