Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 DataType.Date EditorFor Outputting the Wrong Class in HTML
    text
    copied!<p>I have an MVC3 project. I have 2 model classes. Lets call them FooYes and FooNo.</p> <p>I created controllers for each.</p> <p>I created CRUD views for both.</p> <p>I then implemented the jQuery DatePicker according to <a href="http://blogs.msdn.com/b/stuartleeks/archive/2011/01/25/asp-net-mvc-3-integrating-with-the-jquery-ui-date-picker-and-adding-a-jquery-validate-date-range-validator.aspx" rel="nofollow">this link</a>. I only implemented the picker part and not the validation.</p> <p>In my FooYes edit.cshtml the date picker works fine. In the edit.cshtml for FooNo it doesn't.</p> <p>The only difference I found is in the classes that get output for the models:</p> <p>FooYes looks like this in the final html:</p> <pre><code>&lt;input class="date" </code></pre> <p>FooNo looks like this:</p> <pre><code>&lt;input class="text-box single-line" </code></pre> <p>Here is the model for FooYes:</p> <pre><code> [Display(Name = "Creation Date")] [DataType(DataType.Date)] public virtual DateTime CreationDate { get; set; } </code></pre> <p>Here is the model for FooNo:</p> <pre><code> [Display(Name = "Expiration Date")] [DataType(DataType.Date)] public virtual DateTime ExpirationDate { get; set; } </code></pre> <p>As you can see the declaration is the same in the model, so that can't be it. I even tried copy and paste the ExpirationDate property from FooNo into FooYes and duplicated all the stuff from FooNo to FooYes inside of FooYes and it WORKED then. So it is not the code in the model</p> <p>Here is the code from the .cshtml:</p> <pre><code> &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.CreationDate) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.CreationDate) @Html.ValidationMessageFor(model =&gt; model.CreationDate) &lt;/div&gt; </code></pre> <p>The only thing different between this and the other is the name of the field.</p> <p>When I look at the source html in the final result the headers, includes, links, everything is exactly the same except in the one that doesn't work the class= is set to the text thing instead of date.</p> <p>I am totally confused. Anyone have any ideas what would cause this?</p>
 

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