I am using below given class model (MVC 3 using C#) to register an employee. Password/Confirm password fields are used at the time of new registration.
When I edit an existing employee, I don’t want to update/fill their password/confirm password again, but because of given validations (on password and confirm password) it doesn’t let me update rest of the information for employee.
public class EmployeeModel
{
....
....
[Required(ErrorMessage = "Password is must")]
[Display(Name = "Password")]
[MaxLength(20, ErrorMessage = "Password can be maximum 20 chars long")]
[StringLength(20, ErrorMessage = "Password can be maximum 20 chars long")]
[MinLength(5, ErrorMessage = "Not a valid password, must be atleast 5 chars long")]
public string Password { get; set; }
[Compare("Password", ErrorMessage = "Password and Confirm password do not match")]
public string ConfirmPassword { get; set; }
....
....
}
My questions are: Should I create another model class for editing an employee (This new model will not have password/confirm password field)? But I find it problematic because this kind of situation can arise with some other modules as well and I don’t want to end up having two model classes for each module.
OR Should I load the password/confirm password field while editing but hide them from user ?
Do above steps make sense? What other ways are possible ?
there is concept of viewmodal. Create separate modal for every view to avoid such situation