Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC4 Project with HTML5 Semantic markup HtmlHelper.EditorFor uses HTML5 input types

I have a ASP.NET MVC4 project with HTML5 semantic markup enabled. When using @Html.EditorFor(m => m.MyDateTimeField) the output is an input with type="datetime". I want to be able to stop EditorFor from generating HTML5 markup. How can I do this?

This is only a problem in Opera at the moment because other browsers (as far as I know) don't support type="datetime". I have a jQuery datepicker on the field so in Opera I get both the jQuery datepicker and the browser datepicker.

I can fix using any of:
a. Use js to change the input type
b. Use Html.TextBoxFor(m => m.MyDateTimeField)
c. Use a custom editor template
d. Use modernizr to detect if datetime is supported and if so, don't use jQuery datapicker

The solution I want is to disable HTML5 generation in HtmlHelper.EditorFor. I want HtmlHelper.EditorFor to function the same way it would if I hadn't ticked the "html5 semandtic markup" checkbox on project creation.

EDIT: After a bit more searching, I've come across the DataTypeAttribute which I can apply on my model fields to force them to be rendered as input type="text" rather than the html5 match. This is a potential fix, but it is less than ideal. Surely there must be a switch somewhere to turn off html5 in EditorFor (and equivalent helpers)?

A bit more info: I have two projects. The first one was created with "Html5 semantic markup" on, the other without. The first one uses html5 input types when using EditorFor, the second does not. I need to stop the first project EditorFor behaving the way is does without removing the EditorFor. There must be a setting somewhere?

like image 773
Paul Fleming Avatar asked Oct 08 '22 01:10

Paul Fleming


1 Answers

The problem is in one of the project the package references are not updated properly and hence you are seeing the html5 semantic rendered.

This issue happens when you upgrade the ASP.NET MVC beta version to RC and there two ways you could solve the problem either updating all the packages through Nuget or manually add the reference to assemblies.

The issue and solution is clearly explained by Scott here.

like image 68
VJAI Avatar answered Oct 13 '22 09:10

VJAI