[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>
我故意插入虚假的电子邮件,以便错误消息显示在页面上,但它永远不会出现,如果我将其留空,则所需的错误消息会按预期显示。如何才能将有效的电子邮件地址错误显示在页面上,而不是仅仅抛出异常?
答案 0 :(得分:1)
按照polybios
的提法进行尝试模型
[EmailAddress(ErrorMessage = "A Valid Email Address is Required.")]
[Required(ErrorMessage = "Email Address is Required.")]
public string email { get; set; }
答案 1 :(得分:0)
尝试
[EmailAddress(ErrorMessage = "A Valid Email Address is Required.")]
而不是
[DataType(DataType.EmailAddress, ErrorMessage = "A Valid Email Address is Required.")]
答案 2 :(得分:0)
在页面中添加以下javascript。
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
web.config文件中的请添加/检查以下标记
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
要么 mvc [DataType(DataType.EmailAddress) no validation 请尝试以上两件事,请告诉我