0
<input class="datepicker" data-date-format="dd/mm/yyyy" data-val="true" data-val-date="The field Date must be a date." data-val-required="The Date field is required." id="Date" name="Date" type="text">

i have specified data-date-format="dd/mm/yyyy" as guided here. https://github.com/eternicode/bootstrap-datepicker#example

The problem is it is not allowing dd/mm/yyyy format to pass through. I am using asp.net mvc if it matters.

4

1 に答える 1

2

モデルでは、フィールドに次のデータ注釈が設定されていますか?

    [DataType(DataType.Date), DisplayFormat(NullDisplayText="", DataFormatString = " {0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    [Column(TypeName = "Date")]
    public DateTime myDate { get; set; }

また、system.web の下の web.config にも必要です。

<globalization culture="en-AU" uiCulture="en-AU" />

クライアント側の検証を行う場合は、https://github.com/jquery/globalizeも含める必要があります。

<script type="text/javascript" src="/content/scripts/globalize.js"></script>
<script type="text/javascript" src="/content/scripts/globalize.culture.en-AU.js"></script>

最後に、Date フィールドの EditorTemplate を作成します。

/Views/Shared/EditorTemplates/date.cshtml:

@model DateTime
@Html.TextBox("", Model.ToShortDateString(), new { @class = "datepicker"})
于 2013-09-22T22:40:52.733 に答える