View Full Version : [CLOSED] Cannot set the date in a DateFieldFor control

Dec 15, 2013, 9:30 AM

There appears to be a bug with the DateFieldFor control which stops you being able to set the date through javascript.

I have a DateFieldFor:

Html.X().DateFieldFor(m => model.DateOfBirth)
.LabelAlign(LabelAlign.Top).FieldLabel("Date of Birth")

And I am trying to set the value of field with the following javascript line:


I have the user.DateOfBirth getting set through an Ajax call, so the DateOfBirth is just a .NET DateTime object.

If DateOfBith on user comes through as a standard .NET DateTime object, the DateFieldFor displays a value in the format 'yyyy-MM-ddThh:mm:ss', which then gives a validation error on the field. If I pre-format the .NET DateTime object in the format 'dd/MM/yyyy' which matches that which the field was setup with, it displays in American date format on the page. Same if format the .NET DateTime object in 'yyyy-MM-dd'. If I format the .NET DateTime object as 'yyyy-dd-MM', then it displays OK on the page, but when saved back to the server, it is in American date format.

Dec 16, 2013, 3:45 AM

According to
you should pass to the setValue method a JavaScript Date object or a string in a DataField's Format.

Dec 16, 2013, 6:54 AM

I have tried to set the date with a date formatted to a string in the format 'dd/MM/yyyy', and with a date such as 09/12/2013 (9th December 2013), and your date control is changing it to 12/09/2013, 12th September 2013.

Please note the format on DateFieldFor is formatted to 'dd/MM/yyyy'.

Dec 16, 2013, 2:43 PM
I cannot reproduce with this test case.


using System;
using Ext.Net.MVC;

namespace Work2MVC.Models
public class TestModel
[Field(FieldLabel = "DateField")]
public DateTime DateTimeValue


@model Work2MVC.Models.TestModel

<!DOCTYPE html>
<title>Ext.Net.MVC v2 Example</title>

@Html.X().DateFieldFor(m => m.DateTimeValue).Format("dd/MM/yyyy")


Controller Action

public ActionResult Index()
return View(new TestModel() { DateTimeValue = DateTime.Now });