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