The model item is of type CookMeIndexViewModel, but requires a model item of type IEnumerable

In your view you are using @model IEnumerable<CookMe_MVC.ViewModels.CookMeIndexViewModel> which indicates that the model expected by the View is of type IEnumerable of CookMeIndexViewModel. However in the controller you are passing an object of type CookMeIndexViewModel as a model return View(viewModel); hence the error. Either change the view to have @model CookMe_MVC.ViewModels.CookMeIndexViewModel or pass a IEnumerable … Read more

How to pass model to partial view

I had the same issue as the OP. From one of the comments, I realized that the second parameter shouldn’t be null, i.e from @model ParentViewModel @Html.Partial(“_Partial”, Model.Child) If Model.Child is null, then Model is passed instead of Model.Child. If there will be cases when the second parameter is null, then you will have to … Read more

Should a service layer return view models for an MVC application?

Generally, no. View models are intended to provide information to and from views and should be specific to the application, as opposed to the general domain. Controllers should orchestrate interaction with repositories, services (I am making some assumptions of the definition of service here), etc and handle building and validating view models, and also contain … Read more

tech