I created a new MVC4 project in VS2012 with the basic template. I created a model class with a DateTime property. I added a default controller that sets the property to DateTime.Today and a default view that displays the editor for this property. I also included the jqueryval script bundle in my layout, they were in my project by default. When I run the project, there is a textbox with the value "2013.12.12. 0:00:00". But when I press submit, it says its invalid.
Comments: Problem is a client-side validation error: Generated code uses the jQuery.Validation [date](http://jqueryvalidation.org/date-method/) method by default. That method is not recommended due to different behavior across browsers and regions. But this is the best MVC and jQuery.Validation can do without additional packages. Solution is to install the jQuery.Validation.Globalize package and extend the jqueryval bundle to include those scripts. Details below. `DisplayFor` is intended for read-only (or delete) views and it uses only the provided `Model` to determine display. `EditorFor` is used in create / update views and in that context the server-side `Model` may contain last-known-good values rather than the attempted submission. `EditorFor` therefore also pays attention to the validation information and to the view data. I will resolve this bug late this week unless you have a specific suggestion for unobtrusive or MVC. (FYI my previous attempted repros failed because nothing created the jqueryval bundle.) Globalize details: ``` C# public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { // See http://stackoverflow.com/questions/19323409/asp-net-mvc-bundle-config-order for more on overriding // default order within this bundle. Bundle validationBundle = new ScriptBundle("~/bundles/jqueryval") { Orderer = new NonOrderingBundleOrderer(), }; validationBundle.Include("~/Scripts/globalize/globalize.js", "~/Scripts/globalize/cultures/globalize.cultures.js", "~/Scripts/jquery.unobtrusive*", "~/Scripts/jquery.validate.js", "~/Scripts/jquery.validate.globalize.js", "~/Scripts/jquery.validate.unobtrusive.js"); bundles.Add(validationBundle); } private class NonOrderingBundleOrderer : IBundleOrderer { public IEnumerable<BundleFile> OrderFiles(BundleContext context, IEnumerable<BundleFile> files) { // do no ordering overrides; trust the provided enumeration return files; } } ``` You may also need `<script>Globalize.culture("hu-HU")</script>` in the relevant layout file.
Comments: Problem is a client-side validation error: Generated code uses the jQuery.Validation [date](http://jqueryvalidation.org/date-method/) method by default. That method is not recommended due to different behavior across browsers and regions. But this is the best MVC and jQuery.Validation can do without additional packages. Solution is to install the jQuery.Validation.Globalize package and extend the jqueryval bundle to include those scripts. Details below. `DisplayFor` is intended for read-only (or delete) views and it uses only the provided `Model` to determine display. `EditorFor` is used in create / update views and in that context the server-side `Model` may contain last-known-good values rather than the attempted submission. `EditorFor` therefore also pays attention to the validation information and to the view data. I will resolve this bug late this week unless you have a specific suggestion for unobtrusive or MVC. (FYI my previous attempted repros failed because nothing created the jqueryval bundle.) Globalize details: ``` C# public class BundleConfig { public static void RegisterBundles(BundleCollection bundles) { // See http://stackoverflow.com/questions/19323409/asp-net-mvc-bundle-config-order for more on overriding // default order within this bundle. Bundle validationBundle = new ScriptBundle("~/bundles/jqueryval") { Orderer = new NonOrderingBundleOrderer(), }; validationBundle.Include("~/Scripts/globalize/globalize.js", "~/Scripts/globalize/cultures/globalize.cultures.js", "~/Scripts/jquery.unobtrusive*", "~/Scripts/jquery.validate.js", "~/Scripts/jquery.validate.globalize.js", "~/Scripts/jquery.validate.unobtrusive.js"); bundles.Add(validationBundle); } private class NonOrderingBundleOrderer : IBundleOrderer { public IEnumerable<BundleFile> OrderFiles(BundleContext context, IEnumerable<BundleFile> files) { // do no ordering overrides; trust the provided enumeration return files; } } ``` You may also need `<script>Globalize.culture("hu-HU")</script>` in the relevant layout file.