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 of CookMeIndexViewModel as model to the view in controller as given below:

public ActionResult Index()
{
        var meals= new List<string> { "Dinner 1", "Dinner 2", "3rd not sure" };
     //create the view model
        var viewModel = new CookMeIndexViewModel
        {
                NumberOfReceipes = meals.Count(),
                ReceipeName = meals
        };
        List<CookMeIndexViewModel> viewModelList = new List<CookMeIndexViewModel>();
        viewModelList.Add(viewModel);
        return View(viewModelList);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)