【问题标题】:Html.TextBoxFor with Format does not work带有格式的 Html.TextBoxFor 不起作用
【发布时间】:2019-03-07 19:14:44
【问题描述】:

由于某种原因,下面代码的格式仍然显示为 dd/mm/yyyy。

    <div class="col-4">
        @Html.TextBoxFor(m => m.BeginDatum, "{0:dd-MM-yyyy}", new { id = "BeginDatum", @class = "form-control float-left key", placeholder = "dd-mm-jjjj" })
    </div>

在视图模型中:

    [Mandatory]
    [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}")]
    public string BeginDatum { get; set; }

我们正在使用 MVC v5.2.3。

没区别

  • 页面在哪个浏览器中显示。
  • 当 DisplayFormatAttribute 被移除时。
  • 从 TextBoxFor 中删除格式时。

【问题讨论】:

    标签: c# asp.net-mvc-5 html.textboxfor


    【解决方案1】:
    [Mandatory]
    [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}")]
    public DateTime BeginDatum { get; set; }
    

    发现问题。类型是字符串,应该是 DateTime。

    【讨论】:

      猜你喜欢
      • 2019-11-09
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多