I need to create textboxes dynamically based on the no. of records present in employeeExperience list which i am passing to view from controller.
1) I have two classes in Model which came from sql databse through entity framework.
public partial class EmployeeExperience
{
public string EmployeeID { get; set; }
public string CompanyName { get; set; }
public int ID { get; set; }
}
& public partial class EmployeeCAddress
{
public string EmployeeID { get; set; }
public string City { get; set; }
public int ID { get; set; }
}
2) Then i created a viewmodel class which contains
public class EmployeeViewModel
{
public EmployeeCAddress empCAddress { get; set; }
public List<EmployeeExperience> empExperience { get; set; }
}
3) in Controller i have created a actionResult like :
public ActionResult ViewRecord(string empID)
{
var empViewModel = new EmployeeViewModel();
empViewModel.empCAddress = db.EmployeeCAddresses.SqlQuery("Select * from EmployeeCAddress where EmployeeID = {0}", empID).FirstOrDefault();
var experience = db.EmployeeExperiences.SqlQuery("Select * from
EmployeeExperience where EmployeeID = {0}", empID).ToList();
if (experience != null)
{
foreach(EmployeeExperience exp in experience)
{
empViewModel.empExperience = experience;
}
}
return View(empViewModel);
}
So far it is populating correct data and sending it to View. I am able to populate values of EmployeeCAddress in view but dont know how to populate EmployeeExperience list in view as well as in javascript.
Is there any way to access this list in jquery or in html so that i can run a loop and create textboxes dynamically based on the no. of records present in this list?