0
[DataType(DataType.EmailAddress, ErrorMessage = "A Valid Email Address is Required.")]
[Required(ErrorMessage = "Email Address is Required.")]
public string email { get; set; }

<div class="row">
    @Html.LabelFor(model => model.email, "Email:")
    @Html.TextAreaFor(model => model.email, new { @Style = "height:20px; width:300px; resize:none;", id = "emailV" })
    @Html.ValidationMessageFor(model => model.email)
</div>

I'm putting in a false email on purpose so the error message shows up on the page but it never does and if I leave it blank then the required error message shows up as expected. How can I get the valid email address error to show up on the page as well instead of just throwing an exception?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364

3 Answers3

1

try this as mentioned by polybios

Model

[EmailAddress(ErrorMessage = "A Valid Email Address is Required.")]
[Required(ErrorMessage = "Email Address is Required.")]
public string email { get; set; }
Community
  • 1
  • 1
Nilesh Gajare
  • 6,302
  • 3
  • 42
  • 73
0

Try

[EmailAddress(ErrorMessage = "A Valid Email Address is Required.")]

instead of

[DataType(DataType.EmailAddress, ErrorMessage = "A Valid Email Address is Required.")]
Stanko
  • 4,275
  • 3
  • 23
  • 51
0

add below javascript in the page.

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>

in the web.config file pls add/check below tags

 <appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>

or mvc [DataType(DataType.EmailAddress) no validation pls try above two thing and pls let me know

Community
  • 1
  • 1
Brijesh
  • 352
  • 5
  • 17