Elvin Mammadov
Elvin Mammadov

Reputation: 27387

How to apply input which has a type email to to HTML Helper in Asp.net MVC3 Razor

How to apply input which has a type email to HTML Helper in Asp.net MVC3 Razor. For example:

 <input type="email" name="name" value=" " placeholder="[email protected]" />

Is there alternative in Razor?

Upvotes: 14

Views: 26588

Answers (3)

Kuntal Ghosh
Kuntal Ghosh

Reputation: 3698

The below code has worked for me perfectly. By default @Html.TextBoxFor creates <input type="text" /> but specifying the type="email" property makes it <input type="email" />

<div class="editor-field">
    @Html.TextBoxFor(model => model.EmailId, new { @class = "popinputbox", placeholder = "Email ID", type = "email" })
    @Html.ValidationMessageFor(model => model.EmailId, "", new { @class = "errormsg" })
</div>

The problem gets solved. BINGO !!

Upvotes: 4

Ufuk Hacıoğulları
Ufuk Hacıoğulları

Reputation: 38488

You can use Html.TextBox method.

@Html.TextBox("name","", new { type = "email", placeholder = "[email protected]" })

Upvotes: 35

Naresh Parmar
Naresh Parmar

Reputation: 462

Use Dataanotations at Model :

[Required]
[DataType(DataType.EmailAddress, ErrorMessage = "Invalid Email Address")]
public string EmailAddress
{
    get;
    set;

}

Upvotes: 11

Related Questions