Я хочу отобразить сегодняшнюю дату в форме создания фильма.
Контроллер:
// GET: Movies/Create
public IActionResult Create()
{
ViewData["IdGenre"] = new SelectList(_context.Genres, "IdGenre", "Name");
return View();
}
// POST: Movies/Create
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Name,DateDeSortie,Stock,IdGenre")] Movie movie)
{
if (ModelState.IsValid)
{
_context.Add(movie);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["IdGenre"] = new SelectList(_context.Genres, "IdGenre", "Name", movie.IdGenre);
return View(movie);
}
Модель:
[DataType(DataType.Date)]
[Display(Name = "Date de sortie")]
[Required(AllowEmptyStrings =false,ErrorMessage ="La date est requise")]
public DateTime? DateDeSortie { get; set; }
Просмотр:
<div class="form-group">
<label asp-for="DateDeSortie" class="control-label"></label>
<input asp-for="DateDeSortie" class="form-control" />
<span asp-validation-for="DateDeSortie" class="text-danger"></span>
</div>
Спасибо за вашу помощь, я застрял на несколько дней