Email model validation with DataAnnotations and DataType

前端 未结 4 1728
说谎
说谎 2020-12-01 06:08

I have following model:

public class FormularModel
{
    [Required]
    public string Position { get; set; }
    [Required]
    [DataType(DataType.EmailAddre         


        
4条回答
  •  萌比男神i
    2020-12-01 06:41

    I think you need to add at html code one componente Html.ValidationMessageFor. This component shows the validation.

    The code may be (using razor):

    @Html.TextBoxFor(model => model.Email)
    @Html.ValidationMessageFor(model => model.Email)
    

    try it.

提交回复
热议问题