title: ASP.NET Core - MVC - Model variable in view - null exception
body: <p>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.</p>
  <p><strong>Controller Code</strong> - <em>I create a simple list, then pass it to the view, being explicit about which view</em></p>
  <pre><code>public class TableController : Controller
      {
          public IActionResult Index()
          {
              var modelData = new List&lt;string&gt; {&quot;A&quot;, &quot;B&quot;};
  
              ViewBag.Title = &quot;Tables&quot;;
              
              return View(&quot;/Pages/Table.cshtml&quot;, modelData);
          }
      }
  </code></pre>
  <p><strong>View Code</strong></p>
  <pre><code>@page
  @model List&lt;string&gt;
  
      &lt;div class=&quot;text-center&quot;&gt;
          &lt;h1 class=&quot;display-4&quot;&gt;@ViewBag.Title&lt;/h1&gt;
  
          @if (Model == null)
          {
              &lt;p&gt;There is no data to be displayed&lt;/p&gt;
          }
          else
          {
              &lt;ul&gt;
                  @foreach (string str in Model)
                  {
                      &lt;li&gt;@str&lt;/li&gt;
                  }
              &lt;/ul&gt;
          }
      &lt;/div&gt;
  </code></pre>
  <p>When I set a breakpoint in the Controller the object I pass in as the model parameter is not null:
  <a href="https://i.stack.imgur.com/Wnhsl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wnhsl.png" alt="enter image description here" /></a></p>
  <p>However, when I step through into the view code I get this:</p>
  <p><a href="https://i.stack.imgur.com/YaIuO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YaIuO.png" alt="enter image description here" /></a></p>
  <p>I've looked at a few other &quot;Model is null&quot; posts but they were due <strong>mismatching types</strong> between whats passed in the View() model parameter and whats expected in the view given by the @model declaration.</p>
  <p>It's probably something really simple but I'm not sure where I've gone wrong?</p>