This is my Model:
public class TeamRosterModel
{
public SelectList ManageList { get; set; }
public string Command { get; set; }
}
public class Employee
{
public string FromEmpID { get; set; }
public string EmployeeName { get; set; }
}
This is my view:
@Html.DropDownList("Employee", new SelectList(Model.ManageList, "Value", "Text", Model.ManageList.SelectedValue))
This is my controller to set the drop down list:
List<Employee> objEmployee = new List<Employee>();
for (int i = 0; i < dsManageFor.Rows.Count; i++)
{
string d1 = dsManageFor.Rows[i][0].ToString();
string d2 = dsManageFor.Rows[i][1].ToString();
objEmployee.Add(new Employee { FromEmpID = d1, EmployeeName = d2 });
}
sqlConn.Close();
objTeamModel.ManageList = new SelectList(objEmployee, "FromEmpID", "EmployeeName", 0);
This is my controller code to retrieve selected value:
string value = objTeamModel.ManageList.SelectedValue;
I am able to set the values but not able to retrieve the selected value from the drop down... Please help