Part 86 - ValidationSummary in asp.net mvc
2016-11-13 12:19
1271 查看
In this video, we will discuss displaying all validation errors at one place using validation summary html helper.
A red asterisk (start) should be displayed next to every field that has failed the validation. The output should be as shown below.
![](https://img-blog.csdn.net/20161113122024517?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
We will be working with the example that we discussed in Part
85. Please watch Part 85, before proceeding.
First of all, the validation error messages should be displayed in red color. On the "Edit" view, include a reference to Site.css style sheet.
<link href="~/Content/Site.css" rel="stylesheet" type="text/css"
/>
In site.css there are 3 CSS classes that control the display of validation error messages. Adjust the styles of these classes according to your needs.
field-validation-error
input.input-validation-error
validation-summary-errors
To display all errors at one place, use ValidationSummary() HTML helper.
@Html.ValidationSummary(false, "Please fix the following errors and then submit the form")
To display an asterisk, next to the field that has failed validation, modfiy ValidationMessageFor() html helper as shown below.
@Html.ValidationMessageFor(model => model.Name, "*")
At this point, next to the field that has failed the validation message, a star symbol will be displayed instead of the detailed error message. All the detailed error messages will be displayed using validation
summary.
A red asterisk (start) should be displayed next to every field that has failed the validation. The output should be as shown below.
We will be working with the example that we discussed in Part
85. Please watch Part 85, before proceeding.
First of all, the validation error messages should be displayed in red color. On the "Edit" view, include a reference to Site.css style sheet.
<link href="~/Content/Site.css" rel="stylesheet" type="text/css"
/>
In site.css there are 3 CSS classes that control the display of validation error messages. Adjust the styles of these classes according to your needs.
field-validation-error
input.input-validation-error
validation-summary-errors
To display all errors at one place, use ValidationSummary() HTML helper.
@Html.ValidationSummary(false, "Please fix the following errors and then submit the form")
To display an asterisk, next to the field that has failed validation, modfiy ValidationMessageFor() html helper as shown below.
@Html.ValidationMessageFor(model => model.Name, "*")
At this point, next to the field that has failed the validation message, a star symbol will be displayed instead of the detailed error message. All the detailed error messages will be displayed using validation
summary.
相关文章推荐
- Part 89 - Remote validation in asp.net mvc
- Part 88 - Unobtrusive validation in asp.net mvc
- Part 82 - Creating custom validation attribute in asp.net mvc
- Part 85 - Enable client side validation in asp.net mvc
- Part 81 - Range attribute in asp.net mvc
- Model Validation in Asp.net MVC
- Part 60 - ViewStart in asp.net mvc
- Model Validation in Asp.net MVC
- [Asp.net mvc]Html.ValidationSummary(bool)
- Part 83 - RegularExpression attribute in asp.net mvc
- Part 2 - View engines in asp.net mvc
- Part 54 - T4 templates in asp.net mvc
- Understanding Request Validation in ASP.NET MVC 3
- asp.net mvc 3 unobtrusive client side validation not working in IE
- Part 84 - Compare attribute in asp.net mvc
- CustomValidation in ASP.NET MVC
- How to use ValidationSummary control in asp.net
- 【翻译】Building a Simple Blog Engine with ASP.NET MVC and LINQ - Part 3
- [转贴]ASP.NET:创建Linked ValidationSummary, 深入理解ASP.NET的Validation
- 【翻译】使用ASP.NET MVC 和LINQ建立一个简单的博客 - Part 3