I am trying to track Workers in my database.
I have an entity class:
[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; }
}
I am trying to create a page to add an employee to the database. So I created a ViewModel:
public class EmployeesAddViewModel
{
public Employee employee { get; set; }
}
I created a ViewModel like this because I plan to add other things to the model later that are not in the Employees table. I just wanted to start with this to make sure everything is working correctly.
And I have my page:
<%@ Page Inherits="System.Web.Mvc.ViewPage<EmployeesAddViewModel>" ... %>
<% using (Html.BeginForm("Add", "Employees", FormMethod.Post)) { %>
<%: Html.EditorForModel() %>
<input type="submit" value="Save" />
<% } %>
But when I look at my page, it does not show any form fields for my model, it does not show anything.
Do I need to have fields in my model for each field of an entity, instead of having only the entire Employee class in my model? I do not know what I am doing wrong here.
source
share