[RESOLVED]new to mvc – Question about HTML5

does mvc4 naitively support HTML5 can someone point me to a post that explains how to implement HTML5 with MVC everything i’ve found is from 2010.

Yes, MVC allows you to emit HTML5.

DeadTroll

does mvc4 naitively support HTML5

Yes. Could you provide a bit more detail on exactly what you are trying to do? To ensure that you are targeting HTML5, you might want to make sure that you have the appropriate HTML DOCTYPE element present within your Views / Layout :

<!DOCTYPE html>

Have a link to an example of how to accomplish it?

I have not written any code as of yet. I’m trying to research how I might accomplish it first. IE does @Html.TextBox("SearchString") render html4 or html5 textbox?

There’s no difference.

To indicate that a particular View or document will support HTML5 mark-up, you just need to use the DOCTYPE as previously shown within your Views or Layouts :

<!DOCTYPE html>
<html>
<head>
    <!-- Your Head Content -->
</head>
<body>
    <!-- Your Content -->
</body>
</html>

With regards to the HTML helpers and the markup that they generate, its going to be the same. There really isn’t a difference between an HTML5 <input> element and a HTML4 <input> element (which are both going to be generated by the Html.TextBox() helpers).

Despite what you may have heard, HTML5 isn’t exactly some revolutionary concept that will change everything. It adds support for a variety of new types of elements (such as <article>, <video>, <audio> and many, many more) but unless you are specifically
using those and taking advantage of what they can do, most things are going to be the same. The most common elements like <input>, <div>, <select> and all of the font-related styles have not really changed.

If you are interested in some of the differences in what was added within HTML5, you can see the
available W3 specification here.

Ok, I get that and thank you for the info. If I want to take advantage of input type Date or Number, is there an html helper for that? I have a use for Date, Datetime, Number, Email and tel and I’ve been looking at mvchtmlhelper
class
 and do not see anything that would target the new html5 input types

IIRC the html helpers emit the comparable type attribute based upon the model type being used. But in all honesty ifyou’re targeting HTML5 then you’re doing a lot of your work in JS and the features of the html helpers is diminished. Personally, these days,
I don’t use the html helpers anymore and I just code the HTML I need.

Almost all of the HTML Helpers support a parameter called "htmlAttributes" which can accept an anonymous object that allows you to set these specific values depending on the type of field you intend to render :

@Html.TextBox("DateTextBox","", new { type = "date" })

This would render an <input> element with the appropriate type set specified by your htmlAttributes :

<input id='DateTextBox' name='DateTextBox' type='date' />

If your browser supports the date type, then you might see something like the following :

You can see an example of this here.

BrockAllen

Personally, these days, I don’t use the html helpers anymore and I just code the HTML I need.

I’m in the same boat.

The longer that I use MVC, the more that the HTML Helpers start looking like the dreaded Web Forms Controls. This is especially true of more complex ones like the DropDownList. 

Rion Williams

BrockAllen

Personally, these days, I don’t use the html helpers anymore and I just code the HTML I need.

I’m in the same boat.

So you both code unobtrusive validation

data-val-required

 from hand?

ignatandrei

So you both code unobtrusive validation

data-val-required

 from hand?

It just depends on the scenario, but I don’t mind using the required attribute on it’s own as well as other HTML5-related things like placeholders. If I need some complex client-side validation, I’ll wire it up on my own, but besides that I generally let
MVC spit the model back out with errors (using the ValidationSummary) from the server.

ignatandrei

So you both code unobtrusive validation from hand?

This would be the feature you’d be losing, yes. But as I said, if I have that code elsewhere (or don’t need/wait it) then it feels as if the html helpers are just getting in my way.

so if you are not using the html helpers then what is your preferred method of model binding? 

Html helpers help render validation feedback to the user. I still use model binding to map request data to my action method parameters.

Leave a Reply