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

前端 未结 3 1793
情深已故
情深已故 2021-02-13 16:26

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

 

        
相关标签:
3条回答
  • 2021-02-13 17:01

    You can use Html.TextBox method.

    @Html.TextBox("name","", new { type = "email", placeholder = "example@mail.ru" })
    
    0 讨论(0)
  • 2021-02-13 17:01

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

    0 讨论(0)
  • 2021-02-13 17:03

    Use Dataanotations at Model :

    [Required]
    [DataType(DataType.EmailAddress, ErrorMessage = "Invalid Email Address")]
    public string EmailAddress
    {
        get;
        set;
    
    }
    
    0 讨论(0)
提交回复
热议问题