我有点(无意中)我觉得在某些部分我在视图(.aspx)本身做太多,格式化,连接太多,在一个地方有一些正则表达式替换.
我开始研究一个新的部分,并试图改进我的方法..然后它打我,为什么我不只是制作我的所有视图模型(在/ Models/in .Web项目中)字符串或一个字符串列表在一个推.注意:我不是指我的模型/域,而是指我的ViewModel.
public class FinanceQuoteView
{
public string Provider;
public string Broker; // rather than Broker == null ? "N/A" : Broker.ToUpperCase();
public string Monthly; // rather than Monthly.ToString("C")
public string PaymentTerm; // rather than "1+" + PaymentTerm.ToString();
public string FreeInsurance; // rather than insuranceIncluded ? "Yes" : "No";
public string[] Restrictions;
}
Run Code Online (Sandbox Code Playgroud)
对于表单提交(添加编辑),我使用单独的视图模型来提供控制器操作(表单模型,如果您将在/ Models/Form中).所以FinanceQuoteForm包含双打等...通过活页夹构建.
大家对这种方法的看法是什么?在从域到视图模型的映射中做.ToString("C")太多了吗?
| 归档时间: |
|
| 查看次数: |
877 次 |
| 最近记录: |