Client Validation:-

Using Data annotation in MVC framework client validation for the model properties can be done. Model binder performs server-side validation against each property of the model object when their values are set. Client side validation will happen only if JQuery validation plugs are available.

Consider the below example, Required, string length, Range validation will happen at the client side only if we have “jquery.validate.min.js”

Model class:

    
publicclassEmployeeModel
    {
        [ScaffoldColumn(false)]
        publicstring ID { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 3)]
        publicstring Name { get; set; }

        [Range(18, 60)]
        [Required]
        publicint Age { get; set; }
}

    
    

View:

All the javascripts are bundled and minimized

    
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
    
    

BundleConfig:

    
bundles.Add(newScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));