0
votes

I've got an MVC project with a Layout that has strongly typed model named "Dashboard".

@model Dashboard_v2.Models.Dashboard

This Layout has a RenderBody() method that renders the rest of the pages.

then, on my main page, I have a View that is strongly typed with the Model NewPatient.

on the controller I have bunch of code, and eventually I pass a NewPatient Model to it.

When I try to run this code, I've got an error called :

The model item passed into the dictionary is of type 'Dashboard_v2.Models.NewPatient', but this dictionary requires a model item of type 'Dashboard_v2.Models.Dashboard'.

why does it expects a Dashboard Model, if my page has strongly typed NewPatient Model?

1
Why do you need a Model on a layout View anyway?melancia
Remove the model definition from the layout. The model needs to be defined in the view (you are telling every view that its model must be Dashboard)user3559349
Optionally (i.e. it's a must), read this.Andrei V
ohh.. I see.. Thanks!thormayer
If your wanting to render some details relating to Dashboard in all views, then in the layout use @Html.Action() to call a child action method that returns a partial view based on an instance Dashboarduser3559349

1 Answers

0
votes

One approach is to define a Viewmodel with generic parameter MainViewModel<T>and instance it with appreciated T for the views. Then you can use the MainVewModel properties in Layout and use properties of T in your views.