在我的MVC 3号申请中,使用以下询问:
var items = context.QuoteLines.Include("DaybookVehicles").Where(x => x.EnquiryID == id).GroupBy(x=>x.VehicleID).ToList();
return View(items);
我随后认为,我最先这样做:
@model IEnumerable<myApp.Areas.DayBook.Models.DayBookQuoteLines>
但是,这犯了一个错误:
The model item passed into the dictionary is of type
System.Collections.Generic.List`1[System.Linq.IGrouping`2[System.Int32,myApp.Areas.DayBook
.Models.DayBookQuoteLines]] , but this dictionary requires a model item of type
System.Collections.Generic.IEnumerable`1[myapp.Areas.DayBook.Models.DayBookQuoteLines] .
我在这种情况下如何使用集团? 由于我愿意将我<代码>QuoteLines的每个条目组合到相应的<编码>上。
Edit
资格模式:
public class DayBookQuoteLines
{
[Key]
public int QuoteLineID { get; set; }
public int EnquiryID { get; set; }
public virtual int VehicleID { get; set; }
public virtual DaybookVehicles Vehicle { get; set; }
[Required(ErrorMessage = "This field is required.")]
[Display(Name = "Item Number:")]
[MaxLength(50)]
public string ItemNumber { get; set; }
public string ItemDescription { get; set; }
}
车辆模型:
public class DaybookVehicles
{
[Key]
public int VehicleID { get; set; }
public int EnquiryID { get; set; }
public virtual ICollection<DayBookQuoteLines> QuoteLines { get; set; }
public string vrm { get; set; }
public string make { get; set; }
public string model { get; set; }
public string engine_size { get; set; }
public string fuel { get; set; }
}
我认为,我是正确的,但每辆汽车都能够拿到所附的一批精通品!