使用jQuery Datepicker和ajax即使在设置为GB后也使用了错误的格式 [英] using jQuery Datepicker and ajax uses the wrong format even after setting to GB
问题描述
我的网站上有一个datePicker,我使用该值通过Ajax请求发送到我的ActionResult,它接收到一个viewModel:
I have a datePicker on my site, and i use the value to send via Ajax request to my ActionResult which takes in a viewModel seen:
public int UserID { get; set; }
//1-CreatedBy,2 - AssignedTo, 3 - UpdatedBy
public int UserFilterTypeID { get; set; }
public int TaskTypeID { get; set; }
public int TaskStatusID { get; set; }
public HelperClass.Priority Priority{get; set; }
// 1-DateCreated 2-DateUpdated
public int DateTypeID { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime DateFrom { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime DateTo { get; set; }
datepicker设置如下
the datepicker is set up like this
$('.datepicker').datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
regional: "en-GB"
});
检查ajax参数dateFrom显示2014年12月18日(2014年12月18日) ),但是当在actionResult上查看viewModel中的值时,dateFrom显示01/01/0001 00:00:000(默认日期),好像它无法解析日期,因为它期望美国格式,但是我设置了displayFormat在ViewModel中将dd / mm / yyyy设置为dd / mm / yy,因此应该在GB区域设置中。
我用m odernizr识别浏览器是否支持日期类型,这就是为什么它使用自己的日期选择器在Chrome中工作,但在使用datepicker的FireFox和IE中,错误的日期传递给viewModel,(但在数据参数中的格式正确) ajax请求)
请帮助人们
when the ajax parameters are inspected dateFrom shows 18/12/2014 (18th Dec 2014), but when inspect the values from the viewModel on the actionResult dateFrom shows 01/01/0001 00:00:000 (default date) as if it can't parse the date because its expecting US Format, but i've set displayFormat to dd/mm/yyyy in the ViewModel and set the datepicker settings to dd/mm/yy so should be in GB regional settings.
I use modernizr to recognise if browser supports date types, and this is why it works in Chrome using their own datepicker, but in FireFox and IE using datepicker, the wrong date gets passed to viewModel, (but is in the correct format in the data params of ajax request)
please help people
推荐答案
( ' .datepicker')。datepicker({
dateFormat:' dd / mm / yy',
changeMonth: true ,
changeYear: true ,
区域: en-GB
});
('.datepicker').datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true, regional: "en-GB" });
当检查ajax参数dateFrom显示2014年12月18日(2014年12月18日),但是当检查来自actionResult上的viewModel dateFrom显示01/01/0001 00:00:000(默认日期)好像它无法解析日期因为它期望美国格式,但我在ViewModel中将displayFormat设置为dd / mm / yyyy并将datepicker设置设置为dd / mm / yy所以应该在GB区域设置。
我使用modernizr来识别浏览器是否支持日期类型,这就是为什么它可以在Chrome中使用自己的日期选择器,但在使用datepicker的FireFox和IE中,错误的日期传递给viewModel,(但是在ajax请求的数据参数中格式正确)
请帮助人
when the ajax parameters are inspected dateFrom shows 18/12/2014 (18th Dec 2014), but when inspect the values from the viewModel on the actionResult dateFrom shows 01/01/0001 00:00:000 (default date) as if it can't parse the date because its expecting US Format, but i've set displayFormat to dd/mm/yyyy in the ViewModel and set the datepicker settings to dd/mm/yy so should be in GB regional settings.
I use modernizr to recognise if browser supports date types, and this is why it works in Chrome using their own datepicker, but in FireFox and IE using datepicker, the wrong date gets passed to viewModel, (but is in the correct format in the data params of ajax request)
please help people
这篇关于使用jQuery Datepicker和ajax即使在设置为GB后也使用了错误的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!