标签:提示 summary 手机号码 app table tsp message end hid
attributes:
Attributes | Input Type |
---|---|
[EmailAddress] | type=”email” |
[Url] | type=”url” |
[HiddenInput] | type=”hidden” |
[Phone] | type=”tel” |
[DataType(DataType.Password)] | type=”password” |
[DataType(DataType.Date)] | type=”date” |
[DataType(DataType.Time)] | type=”time” |
许多有用的验证属性都必须引用命名空间: System.ComponentModel.DataAnnotations
IsValid
<span asp-validation-for="Email"></span> HTML5: <span class="field-validation-error" data-valmsg-for="Email" data-valmsg-replace="true"> The Email Address field is required. </span> |
通过这个标签,当用户填写的Email的验证没有通过之后,显示默认错误提示。
使用asp-validation-summary属性的<div>标签
HTML替代: @Html.ValidationSummary
asp-validation-summary | Validation messages displayed |
---|---|
(ValidationSummary).All | Property and model level |
(ValidationSummary).ModelOnly | Model |
(ValidationSummary).None | None |
<div asp-validation-summary="ModelOnly"></div> |
ModelState.AddModelError("TelephoneNumber", "请提供有效的手机号码");
.input-validation-error{
border: 1px solid #FF5252;
}
引入jquery验证js就可以解决:
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}
@Html.ValidationSummary(true)
ModelState.AddModelError(string.Empty, error.Description);
标签:提示 summary 手机号码 app table tsp message end hid
原文地址:http://www.cnblogs.com/maoyazhi/p/6104425.html