Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 364
Daveo Avatar asked Oct 12 '22 13:10

Daveo


1 Answers

You may take a look at the following blog post.

like image 84
Darin Dimitrov Avatar answered Jan 05 '23 12:01

Darin Dimitrov