Extensions for MVC2 strongly typed HTML helpers

  • Thread starter Thread starter Dylan Parry
  • Start date Start date
D

Dylan Parry

Hi,

I’d like to write some HTML helper extensions so that I can use some of
the HTML5 form fields within MVC2. Basically, where I’ve now got:

<%= Html.TextBoxFor(model => model.Date, String.Format("{0:g}",
Model.Date))%>

I’d like to be able to use something like:

<%= Html.DateBoxFor(model => model.Date, String.Format("{0:g}",
Model.Date))%>

and have it create HTML that looks like:

<input type="date" id="Date" name="Date" value="…" />

Likewise, I’d like HTML helpers for url, email, number, and all the
other HTML5 form fields.

I’m just not sure where to start. Ideally someone else would have
already written extensions for these elements, but I can’t find any
anywhere.

Does anyone have a link to a tutorial that explains how to create
strongly-typed HTML helpers? Or failing that, is anyone here able to
point me in the right direction with a bit of starter code?

Cheers,
 
The code is available as a download so in the worst case you could check how
this is done (http://aspnet.codeplex.com/releases/view/41742).

That’s a good point. Thanks!
As a side note which HTML 5 browser do you use ? Does it really have support
for validating type="date" fields ?

I personally use Chrome, which doesn’t currently support all of the
different form fields, but they are being added slowly. I believe that
Opera has full (or close to full) support for the form fields though.

I’m actually building a totally closed CMS for me to manage a site of
mine. As the only user will be me, and I’ll always be using a modern
browser, I can certainly afford to tinker with HTML5 on this project. I
probably wouldn’t use it in the wild though, not unless I could ensure
graceful degradation.
 
Thanks, not targetting this but being curious I just wanted to see some of
those new input type fields in action...
 
Back
Top