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

北城以北 提交于 2019-12-21 03:51:15

问题


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="example@mail.ru" />

Is there alternative in Razor?


回答1:


You can use Html.TextBox method.

@Html.TextBox("name","", new { type = "email", placeholder = "example@mail.ru" })



回答2:


Use Dataanotations at Model :

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

}



回答3:


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 !!



来源:https://stackoverflow.com/questions/16689955/how-to-apply-input-which-has-a-type-email-to-to-html-helper-in-asp-net-mvc3-razo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!