Daveo
Daveo

Reputation: 19902

MVC HTML5 EMAIL tag

I have a model

 [Required(ErrorMessage = "Email required")]
[DataType(DataType.EmailAddress, ErrorMessage = "Please enter valid email address")]
public string Email { get; set; }

From that I want the view to return

 <input type="email" value="" name="Email" id="Email" data-val-required="Email required" data-val="true">  

and also option to use jquery.validate.unobtrusive on the email address without including a regx.

But by default the type="text" and I do not get email validation. I only get required field validation What is the easiest way to do this?

html5.js
or http://deanhume.com/Home/BlogPost/asp-net-mvc-html5-toolkit/29 (I tried this it make the type="email" but ignores by data Annotations so I miss out on my client side validation)

or just make a HTML helper

or can I just manually override the type and add data-val-email to my class

Upvotes: 5

Views: 2997

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039398

You may take a look at the following blog post.

Upvotes: 4

Related Questions