Is the model element passed to the dictionary of type "System.Tuple"?

Here I use Tuple to use two models in my view. But I get the following error

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]]'. 

Here is my View :

 @model Tuple<IEnumerable<MvcApplication1.Models.EventRepository>, IEnumerable<MvcApplication1.Models.SlideShow>> ViewBag.Title = "Home Page"; } 

Controller:

 [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))); } 

Any suggestion?

EDIT: Here I call two partial views inside my view and get this error

  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]'. 

Here is my view

  @model Tuple<IEnumerable<MvcApplication1.Models.EventRepository>, IEnumerable<MvcApplication1.Models.SlideShow>> @Html.Partial("EventDetails") @Html.Partial("SlideShow") 

and partial view 1

 @model List<MvcApplication1.Models.EventRepository> 

partial view 2

 @model List<MvcApplication1.Models.SlideShow> 

Answer: I answered this question (Edit)

+4
source share
3 answers

Edit:

 @model Tuple<IEnumerable<MvcApplication1.Models.EventRepository>, IEnumerable<MvcApplication1.Models.SlideShow>> ViewBag.Title = "Home Page"; } 

To

 @model Tuple<List<MvcApplication1.Models.EventRepository>, IEnumerable<MvcApplication1.Models.SlideShow>> ViewBag.Title = "Home Page"; } 

You define the model as IEnumerable , but you pass List down in your return to Controll Action (Index). You also have an alternative to skip IEnumerable if you want the collection not to be modified in your view.

+4
source

For a new error, you can pass a specific part of the tuple to each particle:

@Html.Partial("EventDetails", Model.Item1)

@Html.Partial("SlideShow", Model.Item2)

But, as @ henk-holterman said, you should probably create a specific look model.

+1
source

The answer for my editing is @model Tuple<List<MvcApplication1.Models.EventRepository>, List<MvcApplication1.Models.SlideShow>>

Since we are returning a view with two collections of objects as a tuple, we need to define both models in partial views

+1
source

Source: https://habr.com/ru/post/1480672/


All Articles