title: DateTime default value ASP.net core
body: <p>For a student project, I want to add default value - in the date field(ReleaseDate) but still have a calendar and the option of choosing a date.</p>
  
  <p><img src="https://i.stack.imgur.com/hU1aV.png" alt="Here is a screenshot of what it looks like"></p>
  
  <p>My code in Models/Post.cs:</p>
  
  <pre><code>[Display(Name = "Release Date")]
  [DataType(DataType.Date)]
  [DisplayFormat(ApplyFormatInEditMode =true, DataFormatString = "{0: yyyy-MM-dd}")]
  
  public System.DateTime ReleaseDate { get; set; }
  </code></pre>
  
  <p>And in View/Posts/Create.cshtml:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;label asp-for="ReleaseDate" class="control-label"&gt;&lt;/label&gt;
      &lt;input asp-for="ReleaseDate" class="form-control" /&gt;
      &lt;span asp-validation-for="ReleaseDate" class="text-danger"&gt;&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I try timur but
  Controllers/PostController.cs</p>
  
  <p>Is see only one define of index:</p>
  
  <pre><code> public async Task&lt;IActionResult&gt; Index()
          {
              return View(await _context.Movie.ToListAsync());
          }
  </code></pre>
  
  <p>And your code:</p>
  
  <pre><code>public IActionResult Index()
  {
      var model = new Post()
      {
          ReleaseDate = DateTime.Today
      };
  
      return View("View", model);
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/xEqLq.png" rel="nofollow noreferrer">I try to put like that</a>
  <a href="https://i.stack.imgur.com/zhmi2.png" rel="nofollow noreferrer">But there is an error (on https://localhost:numbers/Posts</a></p>
  
  <p>Views/Posts/Create.cshtml</p>
  
  <pre><code>@model Portal.Models.Post
  
  @{
      ViewData["Title"] = "Create -";
  }
  
  
  &lt;h1&gt;Create&lt;/h1&gt;
  
  &lt;h4&gt;Post&lt;/h4&gt;
  &lt;hr /&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-md-4"&gt;
          &lt;form asp-action="Create"&gt;
              &lt;div asp-validation-summary="ModelOnly" class="text-danger"&gt;&lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Title" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="Title" class="form-control" /&gt;
                  &lt;span asp-validation-for="Title" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="ReleaseDate" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="ReleaseDate" class="form-control" /&gt;
                  &lt;span asp-validation-for="ReleaseDate" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Description" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="Description" class="form-control" /&gt;
                  &lt;span asp-validation-for="Description" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;input type="submit" value="Create" class="btn btn-primary" /&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
      &lt;a asp-action="Index"&gt;Back to List&lt;/a&gt;
  &lt;/div&gt;
  
  @section Scripts {
      @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
  }
  </code></pre>
  
  <p>And Views/Posts/Index.cshtml</p>
  
  <pre><code>@model IEnumerable&lt;Portal.Models.Post&gt;
  
  @{
      ViewData["Title"] = "Job Rice -";
  }
  
  &lt;!-- Image --&gt;
  &lt;section&gt;
      &lt;div class="container"&gt;
          &lt;div class="full-width-image"&gt;
              &lt;img src="img/background.jpg" alt=""&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/section&gt;
  
  
  
  
  
  &lt;div class="text-center"&gt;
  &lt;h1&gt;&lt;a asp-action="Create"&gt;Create new offer&lt;/a&gt;&lt;/h1&gt;
      &lt;/div&gt;
  
  
          @foreach (var item in Model)
          {
  &lt;section&gt;
      &lt;div class="container"&gt;
          &lt;!-- Heading --&gt;
          &lt;div class="my-5"&gt; &lt;/div&gt;
          &lt;!-- Grid row --&gt;
          &lt;div class="row"&gt;
              &lt;!-- Grid column --&gt;
              &lt;div class="col-sm-12 sm-12"&gt;
                  &lt;!-- Card --&gt;
                  &lt;div class="card"&gt;
                      &lt;div class="card-header text-center colores"&gt;
                          &lt;h4&gt; &lt;i class="fas fa-poll-h"&gt;&lt;/i&gt; &lt;a asp-action="Details" asp-route-id="@item.Id"&gt; @Html.DisplayFor(modelItem =&gt; item.Title) &lt;/a&gt;&lt;/h4&gt;
                      &lt;/div&gt;
                      &lt;!-- Card content --&gt;
                      &lt;form class="card-body"&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-sm-12"&gt;
                                  &lt;div class="text-center"&gt; @Html.DisplayFor(modelItem =&gt; item.Description)&lt;/div&gt;
                                  &lt;div class="float-right"&gt; @Html.DisplayFor(modelItem =&gt; item.ReleaseDate)&lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div&gt;
                                  &lt;a asp-action="Edit" asp-route-id="@item.Id"&gt;Edit&lt;/a&gt; 
                                  &lt;a asp-action="Delete" asp-route-id="@item.Id"&gt;Delete&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/section&gt;
  }
  </code></pre>