将当前日期和时间添加到DatePicker

时间:2019-10-30 17:28:56

标签: razor datetimepicker asp.net-core-2.2

如何在ASP.NET Core 2.2中将当前日期和时间绑定到datetimepicker。

<div class="form-group row">
    <label class="col-sm-2 col-form-label">Issue date and time :</label>
    <div class="col-sm-10">
        <input asp-for="DateTimeValue" class="form-control" required />
    </div>
</div>

public DateTime DateTimeValue { get; set; } = DateTime.Now;

1 个答案:

答案 0 :(得分:0)

只需将value属性设置为默认值的当前日期即可

<input asp-for="DateTimeValue" value="@DateTime.Now.ToString("MM-dd-yyyy hh:mm tt")" 
     class="form-control" required />

然后从获取对象中删除= DateTime.Now