Everything works fine out of the box, but after adding a new controller that returns a strongly typed view using the model ‘MySite.Models.Cars’, i get the an error when calling Html.Partial(“LogOnPartial”) in SiteLayout.cshtml. I call the new view like this:
return View(db.Cars.FirstOrDefault());
This is the error:
The model item passed into the
dictionary is of type
‘MySite.Models.Cars’, but this
dictionary requires a model item of
type ‘MySite.Models.LogOnModel’.
Very frustrating. When i use the new view without supplying a model it works again.
return View();
I setup the exact same conditions in MVC 2/ASPX and it worked just fine. I am not sure whether this is an MVC 2/MVC 3 or ASPX/Razor issue. In fact it might be a late night issue…
Very thankful for any reply.
EDIT:
First line from LogOnPartial.cshtml (i removed the underscore)
@model MySite.Models.LogOnModel
First line from Index.cshtml (new view):
@model MySite.Models.Cars
By default the
_LogOnModel.cshtmlpartial as created by the template is not strongly typed and doesn’t require any model. If you modified it so that it requires a model you will need to pass this model when calling it: