方式一
(V:视图)
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ShowCustomer</title>
</head>
<body>
<div>
<table>
<tr>
<td>姓名:</td>
<td>@Model.Age</td>
</tr>
<tr>
<td>年龄:</td>
<td>@Model.SName</td>
</tr>
</table>
</div>
</body>
</html>
(C:控制器)
public ActionResult ShowCustomer()
{
Customer customer = new Customer() {Id=5,Age=18,SName="Alex",Email="543210@qq.com" };
return View(customer);
}
方式二
(V:视图一)
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ShowCustomer</title>
</head>
<body>
<div>
<table>
<tr>
<td>姓名:</td>
<td>@Model.Age</td>
</tr>
<tr>
<td>年龄:</td>
<td>@Model.SName</td>
</tr>
</table>
</div>
</body>
</html>
(V:视图二)
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ShowCustomer</title>
</head>
<body>
<div>
<table>
<tr>
<td>姓名:</td>
<td>@ViewData.Model.Age</td>
</tr>
<tr>
<td>年龄:</td>
<td>@ViewData.Model.SName</td>
</tr>
</table>
</div>
</body>
</html>
(C:控制器)
public ActionResult showcustomer()
{
Customer customer = new Customer() { Id = 5, Age = 18, SName = "Alex", Email = "543210@qq.com" };
ViewData.Model = customer;
return View();
}