title: Value cannot be null. ASP.NET MVC Dropdown List Fails on Post
body: <p>I am using ASP.NET's Register view and added a dropdown list to hold category as seen below:
  <a href="https://i.stack.imgur.com/RRtch.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RRtch.jpg" alt="Modified Registration Form"></a></p>
  
  <p>This is the code for my view:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.LabelFor(m =&gt; m.AccountCategory, "Account Type", new { @class = "col-md-2 control-label" })
      &lt;div class="col-md-10"&gt;
          @Html.DropDownListFor(m =&gt; m.AccountCategory, new SelectList(Model.AccountCategories, "Id", "Category"), "", new { @class = "form-control" })
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My ViewModel bound to the categories is:</p>
  
  <pre><code>[Required]
      public int AccountCategory { get; set; }
  
      public IEnumerable&lt;AccountCategory&gt; AccountCategories { get; set; }
  </code></pre>
  
  <p>And my I modified the Register controller to accomodate the category field as such:</p>
  
  <pre><code>// POST: /Account/Register
      [HttpPost]
      [AllowAnonymous]
      [ValidateAntiForgeryToken]
      public async Task&lt;ActionResult&gt; Register(RegisterViewModel model)
      {
          var category = _context.Categories.Single(c =&gt; c.Id == model.AccountCategory);
  
          if (ModelState.IsValid)
          {
              var user = new ApplicationUser
              {
                  CategoryId = category.Id,
                  UserName = model.Email,
                  Email = model.Email,
                  FirstName = model.FirstName,
                  OtherName = model.OtherName,
                  LastName = model.LastName
              };
              var result = await UserManager.CreateAsync(user, model.Password);
              if (result.Succeeded)
              {
                  await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
  
                  // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                  // Send an email with this link
                  // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                  // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                  // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking &lt;a href=\"" + callbackUrl + "\"&gt;here&lt;/a&gt;");
  
                  return RedirectToAction("Index", "Home");
              }
              AddErrors(result);
          }
  
          // If we got this far, something failed, redisplay form
          return View(model);
      }
  </code></pre>
  
  <p>But when I click the submit button, I get this error:
  Value cannot be null.
  Parameter name: items</p>
  
  <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <blockquote>
    <p>Exception Details: System.ArgumentNullException: Value cannot be null.
    Parameter name: items</p>
  </blockquote>
  
  <p>Source Error: </p>
  
  <pre><code>Line 15:     @Html.LabelFor(m =&gt; m.AccountCategory, "Account Type", new { @class = "col-md-2 control-label" })
  Line 16:     &lt;div class="col-md-10"&gt;
  Line 17:         @Html.DropDownListFor(m =&gt; m.AccountCategory, new SelectList(Model.AccountCategories, "Id", "Category"), "", new { @class = "form-control" })
  Line 18:     &lt;/div&gt;
  Line 19: &lt;/div&gt;
  </code></pre>
  
  <p>Any assistancce will be greatly appreciated.
  Thanks.</p>