title: asp.net mvc core 2 select value is always 0 in view model
body: <p>I have a select in a view that always returns 0 to my view model, and I don't know why:</p>
  
  <p><strong>View Model:</strong></p>
  
  <pre><code>// CreateLifeInsuranceViewModel.cs
  using InsuranceListManager.Models.EntityFrameworkModels;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  
  namespace InsuranceListManager.Models.ViewModels.Home
  {
      public class CreateLifeInsuranceViewModel
      {
          [Required]
          public int CustomerId;
  
          public IList&lt;CustomerModel&gt; Customers { get; set; }
  
          [Required]
          public string InsuredPersonCPF { get; set; }
      }
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public class HomeController
  {
      public IActionResult CreateLifeInsurance()
      {
          var customers = (
              from c in _db.Customers select c    
          ).ToList();
  
          var model = new CreateLifeInsuranceViewModel
          {
              Customers = customers
          };
  
          return View(model);
      }
  
      [HttpPost]
      [ValidateAntiForgeryToken]
      public async Task&lt;IActionResult&gt; CreateLifeInsurance(CreateLifeInsuranceViewModel model)
      {
          if (ModelState.IsValid)
          {
              var category = _db.InsuranceCategories.Where(c =&gt; c.Id == InsuranceCategoryModel.LIFE_INSURANCE).First();
  
              var insurance = new InsuranceModel
              {
                  CategoryId = category.Id,
                  CustomerId = model.CustomerId
              };
  
              _db.Add(insurance);
              await _db.SaveChangesAsync();
  
              var lifeInsurance = new LifeModel
              {
                  InsuranceId = insurance.Id,
                  InsuredPersonCPF = model.InsuredPersonCPF
              };
  
              _db.Add(lifeInsurance);
              await _db.SaveChangesAsync();
  
              return RedirectToAction(nameof(Index));
          }
  
          return BadRequest(ModelState);
      }
  }
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>@model InsuranceListManager.Models.ViewModels.Home.CreateLifeInsuranceViewModel
  
  @{
      ViewData["Title"] = "New Insurance";
  }
  
  &lt;h1&gt;New Insurance&lt;/h1&gt;
  
  &lt;hr /&gt;
  &lt;form asp-action="CreateLifeInsurance"&gt;
      &lt;div asp-validation-summary="ModelOnly" class="text-danger"&gt;&lt;/div&gt;
      &lt;div class="form-row"&gt;
          &lt;div class="form-group col-sm-6"&gt;
              &lt;label asp-for="CustomerId"&gt;Customer&lt;/label&gt;
              &lt;select class="form-control" asp-for="CustomerId" asp-items="@(new SelectList(Model.Customers, "Id", "Name"))"&gt;
                  &lt;option value=""&gt;Select the customer&lt;/option&gt;
              &lt;/select&gt;
              &lt;span asp-validation-for="CustomerId" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
          &lt;div class="form-group col-sm-6"&gt;
              &lt;label asp-for="InsuredPersonCPF"&gt;Insured Person CPF&lt;/label&gt;
              &lt;input type="text" class="form-control" asp-for="InsuredPersonCPF" placeholder="CPF" /&gt;
              &lt;span asp-validation-for="InsuredPersonCPF" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;input type="submit" value="Create" class="btn btn-primary" /&gt;
          &lt;a class="btn" asp-action="Index"&gt;Cancel&lt;/a&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  
  @section Scripts {
      @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
  }
  </code></pre>
  
  <p>in the rendered HTML, the select has the correct values, as you can see in the screeshot:</p>
  
  <p><a href="https://i.stack.imgur.com/578Rh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/578Rh.png" alt="enter image description here"></a></p>
  
  <p>But for some reason, the value that I receive from this select in the view model is always zero:</p>
  
  <p><a href="https://i.stack.imgur.com/syx9e.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/syx9e.jpg" alt="enter image description here"></a></p>
  
  <p>Also, the asp validation won't catch if I don't select any item from the select.</p>
  
  <p>I've been researching this for the last 4 hours and found not a single similar issue around.</p>
  
  <p>I am using Asp.Net MVC Core 2, .Net Core SDK 2.2, Windows 10 Pro and Visual Studio 2017 Community Edition.</p>