【问题标题】:Add current date and time to DatePicker将当前日期和时间添加到 DatePicker
【发布时间】:2020-02-26 01:45:54
【问题描述】:

如何将当前日期和时间绑定到 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;

【问题讨论】:

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


    【解决方案1】:

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

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

    然后从您的 get-set 对象中删除 = DateTime.Now

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多