I´m trying to get some posts from the database. It works fine when opening in the posts index page but not in the main index. As a partialview, I have created a PostViewModel
for the PostModel
.
Here´s the code:
In Index.cshtml (Post):
@model IEnumerable<Project.Models.Post>
@foreach (var item in Model) { @item.Name }
In Index.cshtml (Main):
@model Project.Models.ViewModels.PostViewModel
@Html.Partial("~/Views/Posts/Index.cshtml", Model)
When I run the project, it complains about a System.NullReferenceException
in the foreach
loop.
How can I solve this problem?