我创建了一个包含三个属性的简单类
ID
Name
Amount
我已将模型的命名空间传递给控制器类,如
public class _1Controller : Controller
{
//
// GET: /1/
Customer objCustomer = new Customer();
public ActionResult Index()
{
ViewData["CurrentTime"] = DateTime.Now.ToString();
return View();
}
public ViewResult DisplayCustomer()
{
Customer objCustomer = new Customer();
objCustomer.ID = 12;
objCustomer.Name = "1001";
objCustomer.Amount = 90.34;
return View("DisplayCustomer", objCustomer);
}
}
当我将控制器类绑定到视图时,如
@model MvcApplication4.Models.Customer
@{
Layout = null;
}
<html>
<head>
<title>DisplayCustomer</title>
</head>
<body>
<div>
The customer id is <%= Model.Id %> <br />
the customer Name is <%= M
</div>
</body>
</html>
当我试图调用类属性时,它没有显示。我在checkbox
将视图绑定到控制器时单击了强类型。感谢您的帮助。