ASP.NET Core - MVC - Bootstrap - Responsive Web Programming Lecture 8: Model Validations

preview_player
Показать описание

Source code repository of this Course:

Playlist of this course: ASP.NET Core MVC Full Course - C# And BootStrap Version - Responsive Web #PROGRAMMING With Tutorials 👨‍💻 (FREE) - 2023:

#ASPNETCORE #WebDevelopment

In Lecture 8:

* How to define custom path and action name for server postbacks with Html.BeginForm
* How to set requirements and validations to model properties
* How to set custom requirement and validation messages to model properties
* How to display requirement and validation results at the user screen at the client side
* How to display validation summary at the client side
* How to write more complex attribute routing
* How to generate a custom validation for model properties with inheriting ValidationAttribute
* What types of requirements there are that we can enforce to model properties
* How to modify display of model attributes
* How to format display of model attributes at the client side
* How to set different input types at the client side with using type property of Html.TextBoxFor

Advanced Techniques in ASP.NET MVC Forms and Validations: A Comprehensive Guide
In Lecture 8, we delve into some more advanced topics relating to ASP.NET MVC, exploring how to work more effectively with forms and validations. Let's dive in.

Custom Path and Action Name for Server Postbacks with Html.BeginForm
In ASP.NET MVC, Html.BeginForm() provides an efficient way to create HTML forms. By default, this function makes a postback to the current controller and action. However, it also allows you to define a custom path and action name for server postbacks by accepting actionName, controllerName, routeValues, and formMethod as parameters. This is extremely useful for specifying a different target for the form submission without needing to redirect the user manually.

Setting Requirements and Validations to Model Properties
One of the core principles of ASP.NET MVC is the Model-View-Controller architecture, where Models are central to interacting with data. You can set requirements and validations to model properties using Data Annotation attributes. Examples of these attributes include [Required], [StringLength], and [RegularExpression]. These attributes can be applied directly to the properties in the model, enforcing the validation rules at both the client and server levels.

Custom Requirement and Validation Messages
The same data annotation attributes that set validation requirements can also be used to customize the error messages displayed when a validation fails. By passing a string parameter to these attributes, you can provide a more descriptive and user-friendly error message. For instance, the [Required] attribute could have a custom message like [Required(ErrorMessage = "Please enter your name")].

Displaying Validation Results at the Client Side
ASP.NET MVC includes built-in HTML helpers to display validation results at the client side. The Html.ValidationMessageFor() helper can be used to display validation messages for specific model properties. This helper function automatically displays the correct error message based on the validation attributes applied to the property.

Displaying Validation Summary at the Client Side
In addition to displaying individual validation messages, you can also display a summary of all validation errors using the Html.ValidationSummary() helper. This function provides a convenient way to show all validation errors at once, and it's particularly useful when you have a form with multiple fields that require validation.

Writing More Complex Attribute Routing
Attribute routing in ASP.NET MVC allows you to specify routes directly in your controllers and actions. While the basic functionality is straightforward, attribute routing also supports more complex routing scenarios. For example, you can define route constraints, generate optional URL parameters, or even create multi-segment routes, providing powerful flexibility for managing your application's URL structure.

Custom Validation with ValidationAttribute Inheritance
In cases where the built-in validation attributes don't meet your needs, you can create your own custom validation by inheriting from ValidationAttribute. After defining your own validation logic in the overridden IsValid method, you can use this custom attribute in your model properties just like the built-in validation attributes.
Рекомендации по теме
Комментарии
Автор

Berke Uğur Öner 225060025

1:43 How we generate model using html form
1:55 Data Annotations
2:20 Running application
3:12 Continuing to DataAnnotations (Model Attributes)
3:40 How to use DataAnnotations
4:10 Remembering what was happening in our code
4:33 Creating Lecture 8 classes
7:53 Using DataAnnotations to change parameter names on UI
9:09 Types of DataAnnotations
9:48 Viewing other Annotations
12:03 Summary of Data Annotations
13:30 Setting placeholder annotation for textbox
14:04 Model Validation and using it in our code
21:40 Testing other suitable validations for our code.
26:20 Fixing errors with ActionName
28:32 Displaying validation errors
28:36 What displaying validation is for?
34:54 Testing application
36:56 Summary of model validations
37:17 Types of Model Validations DataAnnotations
37:40 [Required]
38:06 Testing [Required] in our code
38:35 [StringLength]
38:57 Testing application
39:44 [Range]
40:00 [Compare] validation and using it in our code
42:26 Specific Types
43:14 [RegularExpression]
45:33 Custom Model Validation
46:15 Custom Validation with ValidationAttribute
46:57 Coding Custom validation example, testing application and fixing errors
59:44 Explanation of error
1:00:03 Working result

fvx
Автор

abdulbaki emir türkoğlu 225060028
1:41 How we generate framework using html descriptor
1:53 Information Annotations
2:22 Running Game practical application
3:10 Continuing to Data annotations and how to use them
4:13 Remembering what was happening in our computer code
7:51 Using DataAnnotations to change parametric quantity names on UI
12:02 Sum-Up of Annotations generally
13:31 Setting procurator annotation for textbox
14:02 Framework Establishment and using it in our computer code
21:44 Testing other desirable establishments for our computer code.
26:23 Fixing faults with ActionName
28:31 Displaying establishment faults
28:34 What displaying establishment is for?
34:52 Testing practical application
36:55 Sum-Up of framework establishments
37:13 Cases of Model Validations DataAnnotations
38:02 Testing (Required) in our computer code
38:55 Examination practical application
40:03 Comparability / establishment and using it in our computer code
42:21 Specific Cases
43:13 regex
45:32 Custom Model Establishment
46:13 Custom Validation with ValidationAttribute
46:54 Steganography Usage establishment exemplar, testing practical application and fixing faults
59:43 Account of fault
1:00:01 Workings upshot

emirturkoglu
join shbcf.ru