嗨。或许我有极重的RAD情结,当我第一次弄明白ASP.NET MVC架构之后,我忽然发现,RAD有了希望。大多数情况下,当你的Model不幸被修改了,不得不去修改View。而从Model到View的映射还不得不让人来处理,也就是设计时的处理。Visual studio 2008在我们第一次创建View的时候可以帮一点小忙,而修改根本就无能为力了。其实我的期望比较的现实,大概就是ObjectGrid的ASP.NET MVC版。
例如你的Model可以写成这样:
[ObjectForm(ViewStyle.Table)]
public sealed class Product
{
[Hidden]
public int Id { get; set; }
[TextBox(Caption = "商品名称", Width = 120)]
public string Name { get; set; }
[DropdownList(Caption = "类别", ListCreator = typeof(CategoryLister))]
public ProductCategory Category { get; set; }
[TextBox(Caption = "产地", Width = 120)]
public string ProducingArea { get; set; }
[RadioBox(Caption = "单位", ListCreator = typeof(UnitLister))]
public string Unit { get; set; }
[EditableGrid(Caption = "存货量", AllowAdd = true)]
public IEnumerable(Stock) Stocks{ get; set; }
}
[ObjectForm(ViewStyle.InRow)]
public sealed class Stock
{
[Hidden]
public Product Product { get; set; }
[TextBox(Caption = "产品规格", Width = 120)]
public string Spec { get; set; }
[TextBox(Caption = "数量", Width = 120)]
public int Quanlity { get; set; }
[TextBox(Caption = "单价", Mask = "0.##")]
public double Price { get; set; }
[DatePicker(Caption = "入库日期")]
public Date Warehousing { get; set; }
}
public sealed class Product
{
[Hidden]
public int Id { get; set; }
[TextBox(Caption = "商品名称", Width = 120)]
public string Name { get; set; }
[DropdownList(Caption = "类别", ListCreator = typeof(CategoryLister))]
public ProductCategory Category { get; set; }
[TextBox(Caption = "产地", Width = 120)]
public string ProducingArea { get; set; }
[RadioBox(Caption = "单位", ListCreator = typeof(UnitLister))]
public string Unit { get; set; }
[EditableGrid(Caption = "存货量", AllowAdd = true)]
public IEnumerable(Stock) Stocks{ get; set; }
}
[ObjectForm(ViewStyle.InRow)]
public sealed class Stock
{
[Hidden]
public Product Product { get; set; }
[TextBox(Caption = "产品规格", Width = 120)]
public string Spec { get; set; }
[TextBox(Caption = "数量", Width = 120)]
public int Quanlity { get; set; }
[TextBox(Caption = "单价", Mask = "0.##")]
public double Price { get; set; }
[DatePicker(Caption = "入库日期")]
public Date Warehousing { get; set; }
}