5 people following this project (follow)

Project Description

easyVal leverages ValidationAttributes to automatically generate client side and server side validation code. You can leverage easyVal.dll in any ASP.NET 3.5 WebForms application.

Technologies:

  • System.ComponentModel.DataAnnotations.ValidationAttribute
  • jquery validation

Sample Code

Wire up model to controls
//map WebControl to corresponding Property of Model
MapControlsToModel map = new MapControlsToModel(typeof(Employee));
map.AddMapping(txtFirstName, "FirstName");
map.AddMapping(txtEmail, "Email");
map.AddMapping(txtDesiredSalary, "DesiredSalary");


Model declaration
        public class Employee
        {
            [Required(ErrorMessage = "Last Name is Required.")]
            public string LastName { get; set; }

            public string FirstName { get; set; }

            [Email(ErrorMessage = "Must be a valid email.")]
            public string Email { get; set; }

            [Range(0, 1000000, ErrorMessage = "Desired Salary must be between 0 and 1000000.")]
            [Required(ErrorMessage = "Desired Salary is Required.")]
            public decimal DesiredSalary { get; set; }
        }

Last edited May 23 2010 at 3:56 AM by josephflu, version 13