public ActionResult Employee() { //List<CustomerInfo> oCustomerInfos = DataLayer.GetALLCustomers(); List<Employee> oEmpInfos = DB.GetALLEmpDetails(); var myResult = new { //CustomerList = oCustomerInfos, ProductList = oEmpInfos }; return View(oEmpInfos); // return list of employee }
public static List<employee> GetALLEmpDetails() { try { string connections = System.Configuration.ConfigurationManager.ConnectionStrings["EmployeeContext"].ToString(); SqlConnection conn = new SqlConnection(connections); string query = "select * from Employee"; SqlCommand cmd = new SqlCommand(query, conn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dtEmployees = new DataTable(); da.Fill(dtEmployees); List<employee> oEmpInfos = new List<employee>(); if (dtEmployees != null && dtEmployees.Rows.Count > 0) { foreach (DataRow dr in dtEmployees.Rows) { Employee oEmpInfo = new Employee(); oEmpInfo.EmpId = Convert.ToInt32(dr["EmpId"]); oEmpInfo.EmpName = dr["EmpName"].ToString(); oEmpInfo.Designation = dr["Designation"].ToString(); oEmpInfo.Percentage1 = Convert.ToInt32(dr["Percentage1"]); oEmpInfo.Percentage2 = Convert.ToInt32(dr["Percentage2"]); oEmpInfo.Location = dr["Location"].ToString(); oEmpInfos.Add(oEmpInfo); } } return oEmpInfos; }
@model IEnumerable<Employee> <ul> @foreach(var item in Model) { <h3>@item.EmpName</h3> <p>Designation: @item.Designation <br />Location: @item.Location </p> <hr /> } </ul>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)