Html – Is it possible to set type of input generated by TextBoxFor

asp.net-mvc-3html

I am using ASP.NET MVC 3 TextBoxFor in a form and would like to use type="email" for easier input for at least some mobile devices but cannot find how to set it using TextBoxFor. Is this not easily possible?

In View

@Html.LabelFor(m => m.Email)
@Html.TextBoxFor(m => m.Email)

In model

[StringLength(50)]
public string Email { get; set; }

(Already using a data annotation to protect size constraint in DB)

Best Answer

Try to use

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

http://msdn.microsoft.com/en-us/library/ee703538.aspx (htmlAttributes)