这里正在实现 Tuple 以在我的视图中使用两个模型。但是出现以下错误
The model item passed into the dictionary is of type
'System.Tuple`2[System.Collections.Generic.List`1[MvcApplication1.Models.EventRepository],System.Collections.Generic.List`1[MvcApplication1.Models.SlideShow]]',
but this dictionary requires a model item of type
'System.Tuple`2[System.Collections.Generic.IEnumerable`1[MvcApplication1.Models.EventRepository],System.Collections.Generic.IEnumerable`1[MvcApplication1.Models.SlideShow]]'.
这是我的观点:
@model Tuple<IEnumerable<MvcApplication1.Models.EventRepository>, IEnumerable<MvcApplication1.Models.SlideShow>>
ViewBag.Title = "Home Page";
}
控制器:
[HttpPost]
public ActionResult Index(string SearchParam)
{
EventRepository objcheckout = new EventRepository();
objcheckout.GetEventDetails(SearchParam);
SlideShow SS = new SlideShow();
SS.GetSlideDetail(SearchParam);
return View(Tuple.Create(objcheckout.GetEventDetails(SearchParam), SS.GetSlideDetail(SearchParam)));
}
有什么建议吗?
编辑: 这里在我的视图中调用两个部分视图并收到此错误
The model item passed into the dictionary is of type
'System.Tuple`2[System.Collections.Generic.List`1[MvcApplication1.Models.EventRepository],System.Collections.Generic.List`1[MvcApplication1.Models.SlideShow]]',
but this dictionary requires a model item of type
'System.Collections.Generic.List`1[MvcApplication1.Models.EventRepository]'.
这是我的看法
@model Tuple<IEnumerable<MvcApplication1.Models.EventRepository>, IEnumerable<MvcApplication1.Models.SlideShow>>
@Html.Partial("EventDetails")
@Html.Partial("SlideShow")
和 局部视图 1
@model List<MvcApplication1.Models.EventRepository>
局部视图 2
@model List<MvcApplication1.Models.SlideShow>
Answer:
我已经回答了这个问题(编辑)