62,046
社区成员
发帖
与我相关
我的任务
分享
// 数据库对应的实体类
public class Data1Entity
{
public decimal Price { get; set; }
public int Num { get; set; }
}
// Action / View 对应 ViewModel 类
public class TheViewModel
{
public decimal Price { get; set; }
public int Num { get; set; }
public decimal Amount { get; set; }
}
// Controller 中的 Action 方法
public ActionResult Index()
{
TheViewModel vm = new TheViewModel();
Data1Entity d = GetData1Entity(); // 通过 BL / DAL 获取
vm.Price = d.Price;
vm.Num = d.Num;
vm.Amount = d.Price*d.Num;
return View(vm);
}
我也初学,找机会想多讨论一下,加深理解,如果理解错误,希望大家指正