c# - 在日期选择器中显示日期时间
问题描述
在我的 mvc 应用程序中,我有一个 datepicker 控件,并且该控件不会从数据库中读取值。
模型:
[DisplayFormat(DataFormatString = "{0:dd'.'MM'.'yyyy}", ApplyFormatInEditMode = true, ConvertEmptyStringToNull = false)]
public DateTime? myDate { get; set; }
看法:
<div class="col-md-6" style="padding-left:0px;padding-right:0px; margin-top: 15px;">
@Html.LabelFor(model => model.myDate, htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-8">
@Html.EditorFor(model => model.myDate, new { htmlAttributes = new { @class = "form-control datepicker", @type = "date" } })
@Html.ValidationMessageFor(model => model.myDate , "", new { @class = "text-danger" })
</div>
模型中的值:model.myDate.Date {14.02.2019 0:00:00}
在它显示的视图上
dd.mm.yyyy 没有任何值。
保存工作正常。
解决方案
我认为问题可能出在DataFormatString
.
尝试更换:
DataFormatString = "{0:dd'.'MM'.'yyyy}"
有了这个:
DataFormatString = "{0:dd.MM.yyyy}"
推荐阅读
- javascript - getElementsByTagName 的错误用例?
- wordpress - 从后端 woocommerce 添加时立即共享产品
- python-3.x - Python - 列表索引必须是整数或切片,而不是 str
- php - 将文件写入新创建的文件夹时访问被拒绝
- ruby-on-rails - 设计令牌身份验证使用密码重置令牌查找用户
- ios - URL 图像不适用于 Swift Playgrounds 中的 UIButton
- swift - 如何在 Cocoa 应用程序中设置自定义标签顺序
- jbpm - 无法访问 jBPM 控制台
- java - Java Spring/Apache POI/THymeleaf - 从 MSWord 到 HTML 的格式化样式
- scala - 我们如何模拟具有泛型返回类型和隐式参数的 scala 方法?