【问题标题】:MVC 5.2 How to set default value for datetime-local?MVC 5.2 如何为本地日期时间设置默认值?
【发布时间】:2020-07-02 10:03:25
【问题描述】:
 @Html.EditorFor(m => m.DateOfAcception, new
                {
                    htmlAttributes = new { type = "datetime-local", required = "required" },
                    @class = "form-control datepicker",
                    @value = DateTime.Now.ToString()
                })

我得到了类似的东西,但价值不起作用,我的模型也是

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

但我不能让它以默认值开始。

这是它在 html 中的样子

Novo的部分只是@Html.EditorFor(m => m.DateOfAcception) 如果左侧部分可以以某种方式以该值开头

【问题讨论】:

    标签: c# .net asp.net-mvc razor


    【解决方案1】:

    您应该使用 TextBoxFor 并输入国际时间,然后 Razor 会将其转换为本地日期时间。我希望这能回答你的问题。

      @Html.TextBoxFor(x => x.DateOfAcception, "{0:yyyy-MM-ddTHH:mm:ss}", new
                           {
                               @class = "form-control",
                               required = "required",
                               @type = "datetime-local"
                           })
    

    【讨论】:

      猜你喜欢
      • 2010-09-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      • 2022-01-09
      相关资源
      最近更新 更多