title: How to make DateTime bind to RazorPages ViewModel?
body: <p>I have an ASP Core 2.2 project that uses RazorPages, I am binding some data, some of which I send to the client, the client needs to edit this data where required before sending it back.</p>
  
  <p>This works for everything perfectly fine until I want to bind a DateTime object. The data is bound to the HTML datetime-local control as expected, and according to the network traffic, it is sent back in the POST requests form data, however the DateTime object in the OnPost always reads as 01/01/0001</p>
  
  <p>I have already checked this in other browsers in case this was the issues. FireFox doesn't even render datetime-local correctly (its just a textbox, and not a date picker).</p>
  
  <p>I have also tried sending the DateTime object as local and UTC time, and I have set my culture to en-GB as this is where I am.</p>
  
  <p>My code for this is as follows:</p>
  
  <pre><code>RequestLocalizationOptions localizationOptions = new RequestLocalizationOptions
  {
      SupportedCultures = new List&lt;CultureInfo&gt; { new CultureInfo("en-GB") },
      SupportedUICultures = new List&lt;CultureInfo&gt; { new CultureInfo("en-GB") },
      DefaultRequestCulture = new RequestCulture("en-GB")
  };
  
  app.UseRequestLocalization(localizationOptions);
  </code></pre>
  
  <p>StartAt is being set for each line as:</p>
  
  <pre><code>StartAt = DateTime.Now.ToUniversalTime(),
  </code></pre>
  
  <p>and is being bound on the view like this:</p>
  
  <pre><code>&lt;input asp-for="@Model.CreationData.DataLines[lnNo].StartAt" class="form-control"/&gt;
  </code></pre>
  
  <p>The entire bound object is:</p>
  
  <pre><code>public class JobCreationData
  {
      [Required]
      public string Name { get; set; }
  
      [Required]
      public string Description { get; set; }
  
      public int SelectedJobWorkflow { get; set; }
  
      public List&lt;JobCreationDataLine&gt; DataLines { get; set; } = new List&lt;JobCreationDataLine&gt;();
  
      public class JobCreationDataLine
      {
          public int WorkflowVersionId { get; set; }
          public string WorkflowVersionCode { get; set; }
          public string WorkflowVersionDescription { get; set; }
  
          public int SelectedWorkCenterId { get; set; }
  
          public DateTime StartAt;
  
          public List&lt;JobCreationBusinessUnit&gt; BusinessUnits { get; set; }
      }
  
      public class JobCreationBusinessUnit
      {
          public int WantedBusinessUnitId { get; set; }
          public int BusinessUnitId { get; set; }
          public string Alias { get; set; }
          public bool IsRequired { get; set; }
  
          public int SelectedBusinessUnitLineId { get; set; }
      }
  }
  </code></pre>
  
  <p>Below are screenshots that show the HTML5 control, the bound object result is invalid, and the form data that is being sent in the OnPost.</p>
  
  <p><img src="https://i.imgur.com/Yma7b3A.jpg" alt="BindingIssue">
  <img src="https://i.imgur.com/madBsHp.jpg" alt="FormData"></p>
  
  <p>As you can see, I clearly expect the DateTime to bind correctly.</p>
  
  <p>Any ideas?</p>