I have two tables whose structure is as follows:
Employee:
int Id
string EmployeeName
string Department
Department:
int Dept_Id
string Department
Department Table Stores All the Departments with their respective id, and i have a registration form of Employee which contains DropDownList. I want to populate all of the departments as soon as the form loads in the dropdown for that i have to call two models on the same view. I was using tuple but it does not solve my problem. Please help to solve my problem. Code that i am using is :
public ActionResult Index()
{
var model = new model<Employee, Department>(new Employee(), new Department());
return View(model);
}
@model Tuple<MVcEmpApp.Models.Employee, MVcEmpApp.Models.Department>
[HttpPost]
public ActionResult InsertRecord(MyViewModel model)
{
if(ModelState.IsValid)
{
var Employee=new Employee();
Employee.EmployeeName=model.employee.EmployeeName;
Employee.Department=model.employee.Department;
db.AddToEmployee(Employee);
db.SaveChanges();
}
}
Please give any suggestions, Thanks for your answers....