Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom EditorTemplate not being used in MVC4 for DataType.Date
    primarykey
    data
    text
    <p>I'm upgrading an MVC3 application to MVC4 using the <a href="http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806" rel="nofollow noreferrer">instructions from Microsoft</a>. Everything went fairly smoothly - except a few of my date model properties are now rendering differently. For example, one of these properties is defined in the viewmodel like this:</p> <pre><code>[Required(ErrorMessage = "Required")] [DataType(DataType.Date)] [RegularExpression(@"([1-9]|0[1-9]|1[012])...", ErrorMessage = "Format is mm/dd/yyyy")] [FormatHint("mm/dd/yyyy")] [InputSize("small")] public string Date { get; set; } </code></pre> <p>Before upgrading to MVC4, this would be rendered via calling <code>@Html.EditorFor(m =&gt; m.Date)</code> which would use a custom EditorTemplate - the <code>String.cshtml</code> template (since it's a string!). I have some custom data annotations that formats the html so it utilizes a field layout, jQueryUI, and twitter Bootstrap on the client side. The validation is done via jquery validation unobtrusive. Anyhow, this is how it previously rendered:</p> <p><img src="https://i.stack.imgur.com/ie7Fu.png" alt="date editor"></p> <p>Now that I'm using MVC4, the <code>String.cshtml</code> editor template is not being called for this property any longer. It renders like this (in Chrome using the HTML5 editor stuff, I assume):</p> <p><img src="https://i.stack.imgur.com/IUrVN.png" alt="date editor mvc4"></p> <p>The <code>input</code> element looks pretty much the same - all the jQuery validation bits are in there - the only difference seems to be the <code>type</code> attribute is now <code>type="date"</code>, where before it was <code>type="text"</code>.</p> <p>I'd like to continue using the <code>String.cshtml</code> EditorTemplate for this datatype. I'm thinking there might be a data annotation that I can put on the ViewModel property to provide a TemplateHint for <code>@Html.EditorFor(...)</code>. If not this, I'd like to know the custom EditorTemplate that I can write to hijack MVC4's formatting (I've already tried <code>DateTime.cshtml</code> - it's not being called either). If not either of those, then I'm open to suggestions on how to get my property rendering like it used to.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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