In an attempt to learn ASP.NET Core MVC I've made a simple project and am trying to pass a model instance created in the controller to the view.
Controller Code - I create a simple list, then pass it to the view, being explicit about which view
public class TableController : Controller
{
public IActionResult Index()
{
var modelData = new List<string> {"A", "B"};
ViewBag.Title = "Tables";
return View("/Pages/Table.cshtml", modelData);
}
}
View Code
@page
@model List<string>
<div class="text-center">
<h1 class="display-4">@ViewBag.Title</h1>
@if (Model == null)
{
<p>There is no data to be displayed</p>
}
else
{
<ul>
@foreach (string str in Model)
{
<li>@str</li>
}
</ul>
}
</div>
When I set a breakpoint in the Controller the object I pass in as the model parameter is not null:

However, when I step through into the view code I get this:
I've looked at a few other "Model is null" posts but they were due mismatching types between whats passed in the View() model parameter and whats expected in the view given by the @model declaration.
It's probably something really simple but I'm not sure where I've gone wrong?


