2013-09-22 82 views

回答

2

在你的模型,你有以下dataannotation爲您現場設置:

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

你也應該在你的web.config下的System.Web:

<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> 

最後,I C Reate EditorTemplate爲日期字段:

/Views/Shared/EditorTemplates/date.cshtml: 

@model DateTime 
@Html.TextBox("", Model.ToShortDateString(), new { @class = "datepicker"}) 
+0

是的,我做了...在這個.. DataType(DataType.Date)它添加輸入類型日期..我不需要。因爲它增加了瀏覽器默認datepicker –

+0

我已經更新了我的答案與我用來得到這個工作 – Evonet