Do not go db models directly to your views. You are fortunate that you use MVC, so encapsulate it using view models.
Create a view model class as follows:
public class EmployeeAddViewModel { public Employee employee { get; set; } public Dictionary<int, string> staffTypes { get; set; } // really? a 1-to-many for genders public Dictionary<int, string> genderTypes { get; set; } public EmployeeAddViewModel() { } public EmployeeAddViewModel(int id) { employee = someEntityContext.Employees .Where(e => e.ID == id).SingleOrDefault();
Controller:
[HttpGet] public ActionResult Add() { return View(new EmployeeAddViewModel()); } [HttpPost] public ActionResult Add(EmployeeAddViewModel vm) { if(ModelState.IsValid) { Employee.Add(vm.Employee); return View("Index");
Then, finally, in your view (which you can use Visual Studio to scaffold it first), change the inherited type to ShadowVenue.Models.EmployeeAddViewModel. Also, when the dropdowns go, use:
@Html.DropDownListFor(model => model.employee.staffTypeID, new SelectList(model.staffTypes, "ID", "Type"))
and similarly for the gender dropdown
@Html.DropDownListFor(model => model.employee.genderID, new SelectList(model.genderTypes, "ID", "Gender"))
Update for comments
For gender, you can also do this if you can be without gender types in the presentation model proposed above (although, on the other hand, perhaps I would generate this server side in the presentation model as IEnumerable). So, instead of new SelectList... below you should use your IEnumerable.
@Html.DropDownListFor(model => model.employee.genderID, new SelectList(new SelectList() { new { ID = 1, Gender = "Male" }, new { ID = 2, Gender = "Female" } }, "ID", "Gender"))
Finally, another option is the Lookup table. Basically, you store key-value pairs associated with the type of search. One example of a type may be gender, while the other may be a state, etc. I like to structure mine like this:
ID | LookupType | LookupKey | LookupValue | LookupDescription | Active 1 | Gender | 1 | Male | male gender | 1 2 | State | 50 | Hawaii | 50th state | 1 3 | Gender | 2 | Female | female gender | 1 4 | State | 49 | Alaska | 49th state | 1 5 | OrderType | 1 | Web | online order | 1
I like to use these tables when the data set does not change very often, but still needs to be listed from time to time.
Hope this helps!