MVC3 +日期选择器+ UK日期 [英] MVC3 + Datepicker + UK Date
问题描述
花花公子,一直试图很长一段时间就解决这个。我一直在环顾四周,被摆弄周围,但我只是无法得到它的工作!
有关我的出生日期,IM希望接受DD / MM / YYYY日期。不过,只接受MM / DD / YYYY。我应该在哪里进行修正?
我的灵感来自<一个href=\"http://blogs.msdn.com/b/stuartleeks/archive/2011/01/25/asp-net-mvc-3-integrating-with-the-jquery-ui-date-picker-and-adding-a-jquery-validate-date-range-validator.aspx\"相对=nofollow> Jquery的日期选择器1 和 jQuery的日期选择器2 一>。
在我的模型
[数据类型(DataType.Date)
[DisplayFormat(DataFormatString ={0:DD / MM / YYYY},ApplyFormatInEditMode = TRUE)]
[显示(NAME =出生日期)]
公众的DateTime DOB {搞定;组; }
在我看来,pretty直线前进
@ Html.EditorFor(型号=&GT; model.DOB)
有一个编辑器模板被调用时只要使用日期。
@model日期时间?@ Html.TextBox(,型号= NULL Model.Value.ToString(!?DD / MM / YYYY):新{@class =日期})
写了另一个editorhookup,即裁判的Jquery
$(文件)。就绪(函数(){
$('日')日期选择器({DATEFORMAT:DD / MM / YY});
});
任何帮助AP preciated!
我应该在哪里进行修正?
块引用>在编辑器中的模板:
@ Html.TextBox(,ViewData.TemplateInfo.FormattedModelValue,新{@class =日期})
这对于正确的格式显示日期。
有关在POST控制器动作绑定值回你可以写一个自定义模型粘结剂将使用
[DisplayFormat]
属性使用指定格式解析值回一个有效的DateTime实例。Dudes, been trying for very long time on solving this. I have been looking around and been fiddling around but i just cant get it to work!!
For my DOB, im hoping to accept date in dd/mm/yyyy.. however it only accepts mm/dd/yyyy. Where should i make the fix?
I got inspirations from Jquery Datepicker 1 and Jquery Datepicker 2.
In my Model
[DataType(DataType.Date)] [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] [Display(Name = "Date of Birth")] public DateTime DOB { get; set; }
In my View, pretty straight forward
@Html.EditorFor(model => model.DOB)
Have an Editor Template that is called up whenever date is used.
@model DateTime? @Html.TextBox("", Model != null ? Model.Value.ToString("dd/mm/yyyy") : "", new { @class = "date" })
Wrote another editorhookup, that refs Jquery
$(document).ready(function () { $('.date').datepicker({ dateFormat: "dd/mm/yy" }); });
Any help is appreciated!
解决方案Where should i make the fix?
In your editor template:
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "date" })
That's for displaying the date in the correct format.
For binding the value back in a POST controller action you could write a custom model binder that will use the
[DisplayFormat]
attribute to parse the value back to a valid DateTime instance using the specified format.这篇关于MVC3 +日期选择器+ UK日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!