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

前端 未结 3 1006
名媛妹妹
名媛妹妹 2020-12-05 02:19

I am following along with the music store example to try learn ASP.NET MVC. I\'m creating a cookbook application.

I have created my viewmodel that looks like this:<

3条回答
  •  旧巷少年郎
    2020-12-05 02:59

    I got this message when I had a conflict between what the @model directive in the _Layout.cshtml layout view and an "inner page" view.

    The _Layout.cshtml had directive..

    @model MyProject.Models.MyObject
    

    My inner page had...

    @model IEnumerable
    

    I was working on some test / experiment code and hit this issue when I created new controller etc. It was only when I renamed Model Object and compiled afterwards that I found the source of the problem.

    Hope this helps.

    Q.

提交回复
热议问题