Welcome to the HTML5 Inputs for ASP.NET MVC 3 Documents Page

Html5 Inputs for ASP.NET MVC 3 is a toolset that extends the inbuilt HtmlHelper class in MVC to allow easy use of the new HTML 5 Input types. It is indended to be an intermediary system until a version of MVC is provided that handles those inputs supercedes the need for this code.

The code is provided 'as-is', and can be used in any type of project, commercial or otherwise.

Installation.

Installation of the dll's is as simple as referencing them from within a project, and importing the eckersalld.MVC.HtmlHelpers class into a MVC view, at which point you'll find you can access the additional input types via calling the inbuilt Html object, e.g. @Html.TelFor(mymodel=>mymodel.TelephoneNumber).

Metadata

In addition to creating funcrionality for the new input types, I've also expanded on the metadata you can apply to a models parameter to include placeholders and min/max/range values. You will need to reference the eckersalld.MVC.HtmlHelpers.Attributes class and attach them to parameters so:

[Placeholder("Colour")]       
public string Colour { get; set; }

[NumberRange(0, 100, 10, ErrorMessage = "Number should be between 0 and 100, in steps of 10")]
public int Testing2 { get; set; }

There is also a DateRangeAttribute, but please see the caveats section below.

I have not currently set up overloads for these, but using named parameters you can get around having to populate every parameter in NumberRange as they're all optional.

Caveats

I have currently disabled the ability of the date/time input types to have min/max/range values as MVC's inbuilt unobtrustive javascript validation conflicts with them not being numerical in value. You can of course override that decision by manually passing them over as htmlattributes, but would only advise doing so with some method of circumventing the javascript validation.

FAQ's

This will be worked on when I get some questions! ;)

Last edited Aug 2, 2011 at 10:34 AM by eckersalld, version 2

Comments

No comments yet.