我在类库中有以下类
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;
}
}
在我的控制器的create方法中,我有以下几行:
public ActionResult Create()
{
ExpenseEditView ExpenseEdit = new ExpenseEditView(new ExpenseDTO(), GetExpenseTypeList());
return View(ExpenseEdit);
}
当我尝试使用Asp.net mvc Scaffolding模板进行“创建”操作时,它创建了一个空视图而没有为类ExpenseDTO内的属性生成任何代码?
任何人都可以指出我所缺少的内容,以便为ExpenseEditView自动生成模板吗?
答案 0 :(得分:2)
命名视图&#34;创建&#34;什么不是什么让你获得创建行动。相反,你必须:
检查&#34;创建强类型视图&#34;复选框
选择一个Model类。您要使用的模板的下拉列表已启用。
更改&#34;清空&#34; (你得到的)&#34;创建。&#34;
这将解决您的问题。
答案 1 :(得分:0)