方式一
(V:视图)
1 @{ 2 Layout = null; 3 } 4 5 <!DOCTYPE html> 6 <html> 7 <head> 8 <meta name="viewport" content="width=device-width" /> 9 <title>ShowCustomer</title> 10 </head> 11 <body> 12 <div> 13 <table> 14 <tr> 15 <td>姓名:</td> 16 <td>@Model.Age</td> 17 </tr> 18 <tr> 19 <td>年龄:</td> 20 <td>@Model.SName</td> 21 </tr> 22 </table> 23 </div> 24 </body> 25 </html>
(C:控制器)
1 public ActionResult ShowCustomer() 2 { 3 Customer customer = new Customer() {Id=5,Age=18,SName="Alex",Email="543210@qq.com" }; 4 return View(customer); 5 }
方式二
(V:视图一)
1 @{ 2 Layout = null; 3 } 4 5 <!DOCTYPE html> 6 7 <html> 8 <head> 9 <meta name="viewport" content="width=device-width" /> 10 <title>ShowCustomer</title> 11 </head> 12 <body> 13 <div> 14 <table> 15 <tr> 16 <td>姓名:</td> 17 <td>@Model.Age</td> 18 </tr> 19 <tr> 20 <td>年龄:</td> 21 <td>@Model.SName</td> 22 </tr> 23 </table> 24 </div> 25 </body> 26 </html>
(V:视图二)
1 @{ 2 Layout = null; 3 } 4 5 <!DOCTYPE html> 6 7 <html> 8 <head> 9 <meta name="viewport" content="width=device-width" /> 10 <title>ShowCustomer</title> 11 </head> 12 <body> 13 <div> 14 <table> 15 <tr> 16 <td>姓名:</td> 17 <td>@ViewData.Model.Age</td> 18 </tr> 19 <tr> 20 <td>年龄:</td> 21 <td>@ViewData.Model.SName</td> 22 </tr> 23 </table> 24 </div> 25 </body> 26 </html>
(C:控制器)
1 public ActionResult showcustomer() 2 { 3 Customer customer = new Customer() { Id = 5, Age = 18, SName = "Alex", Email = "543210@qq.com" }; 4 ViewData.Model = customer; 5 return View(); 6 }