1 @{ 2 Layout = null; 3 } ViewBagDataToView员工ID员工姓名员工专业员工部门员工电话员工邮件员工籍贯员工住址员工职位员工生日 @foreach (var item in ViewBag.CustomerInfo) 36 { @*@item.Em*@ @item.EmployeeName@item.EmployeeMajor@item.EmployeeDepartment@item.EmployeeTel@item.EmployeeEmail@item.EmployeeJiGuan@item.EmployeeAddress@item.EmployeePosition@item.EmployeeBirthday }
(4)View
1 @using MVCCrud.Areas.JqGridDemo.Models 2 3 @{ 4 Layout = null; 5 } ViewBagDataToView员工ID员工姓名员工专业员工部门员工电话员工邮件员工籍贯员工住址员工职位员工生日@foreach (var item in (List)TempData["CustomerInfo"]) 38 { @item.EmployeeID@item.EmployeeName@item.EmployeeMajor@item.EmployeeDepartment@item.EmployeeTel@item.EmployeeEmail@item.EmployeeJiGuan@item.EmployeeAddress@item.EmployeePosition@item.EmployeeBirthday }
(5)结果
2.4 TempData传递数据
(1)DB表:
(2)Model
CustomerInfo 2 { EmployeeID { get; set; } EmployeeName { get; set; } EmployeeMajor { get; set; } EmployeeDepartment { get; set; } EmployeeTel { get; set; } EmployeeEmail { get; set; } EmployeeJiGuan { get; set; } EmployeeAddress { get; set; } EmployeePosition { get; set; } EmployeeBirthday { get; set; } 13 }
(3)Controller
a.action
ActionResult TempDataToView() 3 { 4 List<CustomerInfo> ltPI = new List<CustomerInfo>(); 5 DataTable dt = GetCustomerInfoToDataTable(); 6 for (int i = 0; i < dt.Rows.Count; i++) 7 { 8 CustomerInfo custInfo = new CustomerInfo(); ].ToString(); ].ToString(); ].ToString(); ].ToString(); ].ToString(); ].ToString(); ].ToString(); ].ToString(); ].ToString(); ].ToString(); 19 ltPI.Add(custInfo); ] = ltPI; 21 } 22 return View(); 23 }
b.ADO.NET 获取CustomerInfo数据
DataTable GetCustomerInfoToDataTable() 3 { conStr = ConfigurationManager.ConnectionStrings[].ConnectionString; ; 7 using (SqlConnection conn = new SqlConnection(conStr)) 8 { 9 conn.Open(); 10 SqlCommand cmd = new SqlCommand(strSql, conn); 11 cmd.ExecuteNonQuery(); 12 SqlDataAdapter sda = new SqlDataAdapter(strSql, conn); 13 DataSet ds = new DataSet(); ); ]; 16 } 17 }
(5)结果
2.5 第三方插件
JqGrid插件:
控制器:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.Mvc; MVCCrud.Areas.JqGridDemo.Controllers 8 { JqGridCustomerInfoController : Controller 10 { ActionResult Index() 13 { 14 return View(); 15 } 16 } 17 }
视图: