I want to create a register form in mvc 4 application. So, when user registers, in that time I want to define user's status (he is programmer or not) and to show (or hide) dynamically some extra fields to fill depending on user's choice.
In default case, all fields seems, if user is not programmer (by unchecking checkbox field), to hide Language, Site and Probation fields. My register model is like this:
public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[StringLength(100, ErrorMessage = "*", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "*")]
public string ConfirmPassword { get; set; }
[Display(Name = "Profession")]
public bool IsProgrammer { get; set; }
[Required]
[Display(Name = "Language")]
public string Language { get; set; }
[Required]
[Display(Name = "Site")]
public string Site { get; set; }
[Required]
[Display(Name = "Probation")]
public string Probation { get; set; }
}
If user is programmer, Language, Site and Probation fields are required, user must fill them.
How should I create Register model that, if user is not programmer, Language, Site and Probation fields not required and let to register ?
My second question is that, how show (hide) fields dynamically, when checkbox is checked (unchecked)?