Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Html.EditorFor How to make attribute type="email"

I can do this easily using a TextBoxFor but how do I do it with an EditorFor?

I figured using the DataAnnotation [DataType(DataType.EmailAddress)] but that doesn't do it.

I don't quite understand what the DataType annotation actually does because it doesn't seem to do anything at all at first glance.

like image 543
Shane LeBlanc Avatar asked Mar 25 '12 21:03

Shane LeBlanc


2 Answers

You can override the HTML Attributes, to which a browser will fallback to type='text' if they do not support it:

@Html.TextBoxFor(m => m.Email, new { @type = "email" })

like image 76
Ankita Singh Avatar answered Sep 16 '22 21:09

Ankita Singh


it seems to be supported now.

@Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control", @type = "email" } })
like image 29
jortizromo Avatar answered Sep 16 '22 21:09

jortizromo