【发布时间】:2013-05-14 09:51:02
【问题描述】:
在我看来,这里正在实现 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:我已经回答了这个问题(编辑)
【问题讨论】:
-
你当然可以(应该)为这个场合写一个特殊的(视图)模型......
标签: c# .net asp.net-mvc asp.net-mvc-4 razor