I have a site that uses a jquery calendar to display events. I have noticed than when using the system from within IE (all versions) ASP.NET MVC will fail to bind the datetime to the action that send back the correct events.
The sequence of events goes as follows.
In every browser other than IE the start and end date come through as:
Mon, 10 Jan 2011 00:00:00 GMT
When IE posts the date, it comes through as
Mon, 10 Jan 2011 00:00:00 UTC
ASP.NET MVC 2 will then fail to automatically bind this to the action method parameter.
Is there a reason why this is happening? The code that posts to the server is as follows:
data: function (start, end, callback) {
$.post('/tracker/GetTrackerEvents', { start: start.toUTCString(), end: end.toUTCString() }, function (result) { callback(result); });
},
I ran into the same problem and I solved it using JavaScript Date()'s .toISOString() function (rather than doing a string replace).
See doc here.
DateTime
and DateTimeOffset
will process this correctly regardless of the broswer sending it (in my limited IE, Firefox, and Chrome testing).
So, I send the date to the controller like so (this is my JS object):
var dateObject = new Date();
dateObject.toISOString()
And the server can parse the data like so (.NET - in the controller):
DateTimeOffset timeInGMT = DateTime.Parse(dateString).ToUniversalTime(); //for the time in GMT
DateTime timeOnClient = DateTime.Parse(dateString); //for time as it was set on the client.
try to replace
start.toUTCString()
with
start.toUTCString().replace('UTC','GMT')
and see if that doesn't fix the problem for you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With