C# 面向实体的MVC模型设计
我试图在我的数据库中跟踪员工 我有一个实体类:C# 面向实体的MVC模型设计,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我试图在我的数据库中跟踪员工 我有一个实体类: [Table(Name = "Employees")] public class Employee { [HiddenInput(DisplayValue = false)] [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)] public int EmployeeID { get; set; } [Co
[Table(Name = "Employees")]
public class Employee
{
[HiddenInput(DisplayValue = false)]
[Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
public int EmployeeID { get; set; }
[Column]
[Required]
public string FirstName { get; set; }
[Column]
[Required]
public string LastName { get; set; }
[Column]
[Required]
public string Email { get; set; }
}
我正在尝试创建一个页面,将员工添加到数据库中。因此,我创建了一个ViewModel:
public class EmployeesAddViewModel
{
public Employee employee { get; set; }
}
我这样创建ViewModel是因为我计划稍后向模型中添加Employees表中没有的其他内容。我只是想从这个开始看看是否一切正常
我有我的网页:
<%@ Page Inherits="System.Web.Mvc.ViewPage<EmployeesAddViewModel>" ... %>
<% using (Html.BeginForm("Add", "Employees", FormMethod.Post)) { %>
<%: Html.EditorForModel() %>
<input type="submit" value="Save" />
<% } %>
但是,当我查看页面时,它不会显示模型的任何表单字段,也不会显示任何内容
我是否需要在模型中为每个实体字段设置字段,而不是在模型中设置整个Employee类?我不知道我做错了什么。你可以调用
Html.EditorFor(m=>m.Employee)
默认编辑器模板不考虑复杂类型属性