我在类库中有以下类
public class ExpenseDTO
{
[Key]
public Int32 ExpenseId { get; set; }
public Int32 ExpenseTypeId { get; set; }
[Display(ResourceType = typeof(Resource), Name = "ExpenseDate")]
[Required(ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "ExpenseDataRequired")]
[DataType(DataType.Date,ErrorMessageResourceName="InvalidDateFormat"
,ErrorMessageResourceType=typeof(Resource))]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime ExpenseDate { get; set; }
[MaxLength(200, ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "ExpenseNoteMaxLength")]
[Display(ResourceType = typeof(Resource), Name = "ExpenseNote")]
public String ExpenseNote { get; set; }
[Required(ErrorMessageResourceType = typeof(Resource), ErrorMessageResourceName = "ExpenseAmountRequired")]
[Display(ResourceType = typeof(Resource), Name = "ExpenseAmount")]
public decimal ExpenseAmount { get; set; }
public ExpenseDTO()
{
ExpenseNote = String.Empty;
}
}
我还有一个 asp.net MVC 4 项目,它有一个名为 ExpenseEditView 的类,其定义如下
public class ExpenseEditView
{
public ExpenseDTO Expense { get; set; }
public IEnumerable<SelectListItem> ExpenseTypeList { get; set; }
public ExpenseEditView(ExpenseDTO Expense, IEnumerable<SelectListItem> ExpenseTypeList)
{
this.Expense = Expense;
this.ExpenseTypeList = ExpenseTypeList;
}
}
在我的控制器的创建方法中,我有以下行:
public ActionResult Create()
{
ExpenseEditView ExpenseEdit = new ExpenseEditView(new ExpenseDTO(), GetExpenseTypeList());
return View(ExpenseEdit);
}
当我尝试使用 Asp.net mvc Scaffolding 模板进行“创建”操作时,它创建了一个空视图,而没有为类 ExpenseDTO 中的属性生成任何代码?
谁能指出我所缺少的,以便可以为 ExpenseEditView 自动生成模板?