简体   繁体   English

如何从 mvc 日期选择器中删除时间并在剃刀视图中设置默认值?

[英]How can I remove time from a mvc datepicker and set a default value in a razor view?

This is my datepicker:这是我的日期选择器:

@Html.EditorFor(model => model.Birthdate, "{dd MM yyyy}", new { htmlAttributes = new { @class = "form-control", @value = DateTime.Now } })

It currently displays the date like this: 01-01-0001 00:00它目前显示这样的日期: 01-01-0001 00:00

Also the default time is wrong.默认时间也是错误的。 I want it to be DateTime.Now as the default.我希望它是 DateTime.Now 作为默认值。

How can I achieve this?我怎样才能做到这一点?

您可以尝试使用type="datetime-local"

<input type="datetime-local" asp-for="Birthdate" value="@DateTime.Now.ToString("s")" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM