我需要根据编号动态创建文本框。我正在传递以从控制器查看的employeeExperience列表中存在的记录的数量。
1)我在Model中有两个类,它们是通过实体框架来自sql databse的。
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)然后,我创建了一个包含
的viewmodel类public class EmployeeViewModel
{
public EmployeeCAddress empCAddress { get; set; }
public List<EmployeeExperience> empExperience { get; set; }
}
3)在控制器中,我创建了一个actionResult,如:
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);
}
到目前为止,它正在填充正确的数据并将其发送到View。我能够在视图中填充EmployeeCAddress的值,但不知道如何在视图以及javascript中填充EmployeeExperience列表。
有没有办法在jquery或html中访问此列表,以便我可以运行循环并根据否动态创建文本框。此列表中有多少记录?