I am new to MVC framework. I have 2 radio buttons and i want at least one should be checked. I want to do it through custom validation, need help?
The field is "usWorkPermit":
My View code:
Do you have US Work Visa ?
@Html.RadioButtonFor(m => m.usWorkPermit,"True") Yes I have
@Html.RadioButtonFor(m => m.usWorkPermit, "False") No I don't
My Model code:
[UsWorkPermitValidation]
public Boolean usWorkPermit { get; set; }
My Controller code:
[HttpPost]
public ActionResult Index(Models.JobApplication jobApplication)
{
if (ModelState.IsValid)
{
}
return View();
}
I created the custom validator which is incomplete. I want to ask how i can force at least one radio button to be checked ??
public class UsWorkPermitValidation : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
// check at least one radio button is checked.
}
}
How to get values of each radio buttons on my custom validator? If i know then then i can easily do the checking ??