0
我正在开发默认文化为en-GB的MVC 5.2应用程序,该应用程序的默认ShortDatePattern为dd/MM/yyyy。我想将日期模式更改为MM/dd/yyyy以查看/编辑模型。以MM/dd/yyyy格式显示日期
显示模型时工作正常。但在编辑模式下显示日期时遇到问题。下面是我的代码 -
视图模型
[Display(Name="License Renewal Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString="{0:MM/dd/yyyy}", ApplyFormatInEditMode=true)]
public DateTime LicenseRenewalDate { get; set; }
.cshtml
@Html.EditorFor(model => model.LicenseRenewalDate, new { htmlAttributes = new { @class="form-control" } })
@Html.ValidationMessageFor(model => model.LicenseRenewalDate, "", new { @class="text-danger" })
正如你可以看到,默认日期格式在编辑框中显示为dd/MM/yyyy,日期选取器控件不允许我更改i吨。 如何设置日期选择器控件的默认日期模式为MM/dd/yyyy?
仅供参考,我使用
jQuery.Validation version - 1.11.1 and
Microsoft.jQuery.Unobtrusive.Validation version - 3.2.3
谢谢!
的Web.config沿选项不起作用。然后我试着用DateTime EdiotrTemplate,但看起来,它没有被调用。我已经在\ Views \ Shared \ EditorTemplates \ DateTime.cshtml中建议添加DateTime.cshtml – iniki
我通过从ViewModel属性中删除[DataType(DataType.Date)]得到了它。该属性呈现type = date的输入控件。 DateTime的Custom EditorTemplate不适用于类型为“date”的输入控件。 – iniki