Noob question: Why wont my Index.cshtml page load the data being passed to it from the controller?
Upfront I should say I'm using ASP.NEt Core 2.0
OK, so I'm build a small test site as a learning experience. My controller Index method consists of:
List<Object> objects = _objectRepository.GetObjects(); return View(objects);
I ran it through the debugger, and know that list is populating with the two objects I have created as initial data, but then when it passes it to my Index.cshtml file, which has this at the top
@model List<Namespace.Models.Object>
when I try to do this:
<ul> @foreach (var object in Model) { <li>@object.Property1</li> <li>@object.Property2</li> } </ul>
I'm getting a Null Reference Exception: Object reference not set to an instance of an object, and it details that foreach() loop, so I'm thinking it has to be an issue with the Model variable right?
Thanks in advance for any help!
0 comments:
Post a Comment