1
When performing the Submit in a form with a date dd/MM/yyyy, the value is converted to the American format in the controller, leaving MM/dd/yyyy. Through the answer of this question, configure globalize to solve this problem. However, the error persists.
Follow below Configured Bundle:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate.js",
"~/Scripts/jquery.validate.globalize.js",
"~/Scripts/jquery.validate.unobtrusive.min.js",
"~/Scripts/jquery.unobtrusive-ajax.js"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/globalize").Include(
"~/Scripts/globalize.js"));
Code to load the Bundles
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/globalize")
@Scripts.Render("~/bundles/jqueryval")
Configuration line in section System.Web
in the Web.Config
<globalization uiCulture="pt-BR" culture="pt-BR" enableClientBasedCulture="true" requestEncoding="UTF-8" responseEncoding="UTF-8" fileEncoding="UTF-8" />
Field datetime in cshtml
@Html.TextBoxFor(model => model.Inicio, "{0:dd/MM/yyyy}", new { @class = "form-control" })
Gypsy, I’ve been using Editorfor because it worked perfectly on Chrome, but the same didn’t happen on Firefox or IE. With Textbox, it was not working in any browser. I will check your link
– Vinícius
I performed the implementation of the topic you posted, but the error persists. In the Javascript log no error appears, previously appeared something related to Globalize.Parse.
– Vinícius
@Vinícius Now it can be the internal validation. See the edition I just put.
– Leonel Sanches da Silva
I did as you indicated, but keep changing the dates in the controller. I updated the question with the Razor field in cshtml.
– Vinícius
Observing the value of the Request["Start"] key, I see that the value comes correctly from html but it is not converted correctly to datetime.
– Vinícius
You can ask your question how Globalize was installed?
– Leonel Sanches da Silva