I have a class, employee, in which the user inputs values for the properties on one screen, and then some more on another screen. The problem I have with this is how to validate these properties? If I put validation attributes for the properties of the class I have a problem. The validation takes place whether the field is displayed on the form or not. So for my Employee class I have had to comment out some of the validation in order to get it to work on 1 screen. It probably won't work on the other. private sealed class Metadata { [HiddenInput(DisplayValue=false)] public int EmployeeId { get; set; }
[DisplayName("Forename")]
[DataType(DataType.Text)]
[Required(ErrorMessage = "Forename is required")]
public string Forename { get; set; }
[DisplayName("Surname")]
[DataType(DataType.Text)]
[Required(ErrorMessage = "Surname is required")]
public string Surname { get; set; }
[DisplayName("Middle Names")]
[DataType(DataType.Text)]
public string Middlenames { get; set; }
//[DisplayName("User Name")]
//[DataType(DataType.Text)]
//[Required(ErrorMessage = "User name is required")]
//public string UserName { get; set; }
[DisplayName("Employee Number")]
[DataType(DataType.Text)]
[Required(ErrorMessage = "EmployeeNumber is required")]
public string EmployeeNumber { get; set; }
[DisplayName("Department")]
[UIHint("DropDownList")]
[Required(ErrorMessage = "You must select a department from a division")]
public int DepartmentId { get; set; }
[DisplayName("User Role")]
[UIHint("DropDownList")]
[Required(ErrorMessage = "You must select a role")]
public int SHP_UserRoleId { get; set; }
//[DisplayName("Email")]
//[DataType(DataType.EmailAddress)]
//[Required(ErrorMessage = "Email is required")]
//[RegularExpression(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$", ErrorMessage = "Not a valid email")]
//[UniqueEmail(ErrorMessage = "User already exists")]
//public string EmailAddress { get; set; }
[DisplayName("End Date")]
public DateTime? EndDate { get; set; }
}