我收到了一个错误:
传递到字典中的模型项的类型为'System.Data.Entity.Infrastructure.DbQuery`1 [jetjourneys.ViewModel.ItineraryPage]',但此字典需要类型为'jetjourneys.ViewModel.ItineraryPage <的模型项/ p>
代码:
public class ItineraryPage
{
public PackageGallery Package { get; set; }
public tblItinerary Itinerarydetail { get; set; }
}
public ActionResult ItineraryPackage(int id)
{
using (travelAndTourismEntities objentity = new travelAndTourismEntities())
{
var query = (from x in objentity.tblItineraries
from y in objentity.PackageGalleries
where x.Imageid == id && y.Imageid == id
select new ItineraryPage { Package = y, Itinerarydetail = x });
return View(query);
}
}
这是我的控制员请帮助我,我犯了错误
答案 0 :(得分:0)
您仍然返回IQueryable
对象而不是实际结果,这应该可以正常工作
public ActionResult ItineraryPackage(int id)
{
using (travelAndTourismEntities objentity = new travelAndTourismEntities())
{
var query = (from x in objentity.tblItineraries
from y in objentity.PackageGalleries
where x.Imageid == id && y.Imageid == id
select new ItineraryPage { Package = y, Itinerarydetail = x });
return View(query.FirstOrDefault()); //Update here
}
}