I have MVC3 web application where we need to populate radio button list with validation. My Model is something like this:
public class EmployeesViewModel
{
public List<Employee> listEmployee { get; set; } //To persist during post
public IEnumerable<SelectListItem> selectListEmployee { get; set; }
[Required]
public Employee selectedEmployee { get; set; }
}
public class Employee
{
public int ID {get; set;}
public string Name {get; set}
public string Department {get; set}
}
I need to populate radiobutton list something like below:
- Employee1ID - Employee1Name - Employee1Department // id - name - department
- Employee2ID - Employee2Name - Employee2Department
- Employee3ID - Employee3Name - Employee3Department
Selected Employee should be stored into "selectedEmployee" field. What is the best or clean way to populate these radio button List in MVC3?
Note: Mainly Looking for two task: 1. storing "Employee" object in each "Input" radio button tag, so that selected employee will be saved to "selectedEmployee" field 2. Best way to mark "Employee" object as required field
Much appreciate your help!
Thanks,