title: ArgumentNullException : Value cannot be null. Parameter name : viewData
body: <p>I have simple login page like this:</p>
  
  <p>Login.cshtml</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@page
  @model GDPR.Views.Account.LoginModel
  @{
  }
  
  @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
  
  
  &lt;html&gt;
  &lt;body&gt;
      &lt;p&gt;Login &lt;/p&gt;
      &lt;form method="post"&gt;
          &lt;div asp-validation-summary="All"&gt;&lt;/div&gt;
          Username: &lt;input asp-for="loginData.Username" value="username" /&gt;&lt;br /&gt;
          Password: &lt;input asp-for="loginData.Password" value="password" /&gt;&lt;br /&gt;
          &lt;br /&gt;
          &lt;input type="submit" value="Login" /&gt;
          @Html.AntiForgeryToken()
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and code behind:</p>
  
  <pre><code>public class LoginModel : PageModel
  {
      [BindProperty] // Bind on Post
      public LoginData loginData { get; set; }
  
      public async Task&lt;IActionResult&gt; OnPostAsync()
      {
          if (ModelState.IsValid)
          {
            .......
              await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);
              return RedirectToPage("/Home/Index");
          }
          else
          {
              ModelState.AddModelError("", "username or password is blank");
              return Page();
          }
      }
  
  
      public class LoginData
      {
          [Required]
          public string Username { get; set; }
  
          [Required, DataType(DataType.Password)]
          public string Password { get; set; }
      }
  }
  </code></pre>
  
  <p>When I run the app I get an error: ArgumentNullException value cannot be null, param name : viewData.</p>
  
  <p><a href="https://i.stack.imgur.com/meCr1.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/meCr1.jpg" alt="enter image description here"></a></p>
  
  <p>What could be the reason for that error?</p>