Unit 4
Unit 4
NET Core-I
DU # 2101CS511
Unit-4
Validations/Data
Annotations, Areas
& Model Binding
Prof. Naimish R Vadodariya
Computer Engineering Department
Darshan University, Rajkot
[email protected]
8866215253
Validations with Data
Annotation
Why Validation?
When we developed any type of application such as web-based or desktop based, in both the
application one is the key part of development is Data Validation or Form Validation.
These validations always ensure us that user fills the correct form of data into the application
so that we can process that data and submit.
Normally users always fill the data with necessary information and submit it or select it. But,
sometimes the user make some mistakes while filling or selecting data.
In this case, form validation is required to ensure that the user always provides the required
information in the proper format which is required for the successful submit the details.
The field value is required.
Please enter valid email
Please Enter Age between 1 to 120 etc.
This type of message known as user defined validations messages.
[Required]
public string Name { get; Empty The Name field is required.
set; }
[Required]
[Display(Name="First Name")] Empty The First Name field is required.
public string Name { get; set; }
[StringLength(10)]
public string Mobile { get; set; } It will allow user to enter max 10 characters
[Compare("Mobile",
ErrorMessage ="Mobile number does not match")] String does not match Mobile number
public string MobileFather { get; set; } does not match
[Required]
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Required]
[StringLength(10)]
public string MobileNo { get; set; }
app.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}“
);
[Area("Branch")]
public class MST_BranchController : Controller
{