Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC DateTime validation failing
    primarykey
    data
    text
    <p>I found a lot of simulair questions but not a good clean solution that is working. I see a lot of custom code for getting this to work but why is that? Should this not working from the start?</p> <p>What I think is strange, is that in IE9 it works but in Firefox and Chrome it is failing. Everytime that im trying in Firefox or Chrome, I get the message "The field Birthday must be a date".</p> <p>When I try the code below in a new MVC 4 RTM project, I can't get it to work. I see the DateTime.Now default as dd-MM-yyyy (Holland) in all the browsers but I can't submit it in Firefox and Chrome.</p> <p>The globalization tag isn't set in web.config so it must be using the default. Im from Holland so it should get the client culture I guess.</p> <pre><code>public class RegisterModel { [Required] [Display(Name = "User name")] public string UserName { get; set; } [Required] [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)] //[DataType(DataType.Date)] public DateTime Birthday { get; set; } } [AllowAnonymous] public ActionResult Register() { RegisterModel vm = new RegisterModel() { Birthday = DateTime.Now }; return View(vm); } [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { //WebSecurity.CreateUserAndAccount(model.UserName, model.Password); //WebSecurity.Login(model.UserName, model.Password); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); } </code></pre> <p>Markup</p> <pre><code>&lt;!-- language: lang-none --&gt; @model DateTimeWithDatePicker.Models.RegisterModel @{ ViewBag.Title = "Register"; } &lt;hgroup class="title"&gt; &lt;h1&gt;@ViewBag.Title.&lt;/h1&gt; &lt;h2&gt;Create a new account.&lt;/h2&gt; &lt;/hgroup&gt; @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary() &lt;fieldset&gt; &lt;legend&gt;Registration Form&lt;/legend&gt; &lt;ol&gt; &lt;li&gt; @Html.LabelFor(m =&gt; m.UserName) @Html.TextBoxFor(m =&gt; m.UserName) &lt;/li&gt; &lt;li&gt; @Html.LabelFor(m =&gt; m.Birthday) @Html.EditorFor(m =&gt; m.Birthday) &lt;/li&gt; &lt;/ol&gt; &lt;input type="submit" value="Register" /&gt; &lt;/fieldset&gt; } @section Scripts { @Scripts.Render("~/bundles/jqueryval") } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload