对于学生项目,我想在日期字段(ReleaseDate)中添加默认值,但仍然有日历和选择日期的选项。

我在 Models/Post.cs 中的代码:
[Display(Name = "Release Date")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode =true, DataFormatString = "{0: yyyy-MM-dd}")]
public System.DateTime ReleaseDate { get; set; }
Run Code Online (Sandbox Code Playgroud)
在 View/Posts/Create.cshtml 中:
<div class="form-group">
<label asp-for="ReleaseDate" class="control-label"></label>
<input asp-for="ReleaseDate" class="form-control" />
<span asp-validation-for="ReleaseDate" class="text-danger"></span>
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试 timur 但 Controllers/PostController.cs
只能看到索引的一个定义:
public async Task<IActionResult> Index()
{
return View(await _context.Movie.ToListAsync());
}
Run Code Online (Sandbox Code Playgroud)
还有你的代码:
public IActionResult Index()
{
var model = new Post()
{
ReleaseDate = DateTime.Today
};
return View("View", model);
}
Run Code Online (Sandbox Code Playgroud)
我尝试这样写 但是有一个错误(在 https://localhost:numbers/Posts
视图/帖子/Create.cshtml
@model Portal.Models.Post
@{
ViewData["Title"] = …Run Code Online (Sandbox Code Playgroud)