here is what appears:
I used the template and i passed my model onto my view and i notice that they get those white spaces. I've been trying to default a DropDownList
for my gender but somehow, they don't work. I was trying to debug and thought that maybe it's because of those weird white spaces. (All of them have it except department).
How do i resolve the issue?
I would also like to add that i use Entity Framework
.
Model
[Table("carl")]
public class Employee
{
public int id { get; set; }
[DisplayName("First Name")]
[Required(ErrorMessage = "First name is required")]
public string firstname { get; set; }
[DisplayName("Last name")]
[Required(ErrorMessage = "Last name is required")]
public string lastname { get; set; }
[Required(ErrorMessage = "Gender is required")]
public string gender { get; set; }
[DisplayName("Department")]
[Range(1, 3)]
[Required(ErrorMessage = "Dep name is required")]
public int department { get; set; }
public List<String> Players = new List<String> { "test", "test" };
}
Controller
[HttpGet]
public ActionResult Edit(int id)
{
EmployeeContext emp = new EmployeeContext();
Employee sel = emp.Employees.Single(x => x.id == id);
return View(sel);
}
View
@model MvcApplication6.Models.Employee
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Employee</legend>
@Html.HiddenFor(model => model.id)
<div class="editor-label">
@Html.LabelFor(model => model.firstname)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.firstname)
@Html.ValidationMessageFor(model => model.firstname)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.lastname)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.lastname)
@Html.ValidationMessageFor(model => model.lastname)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.gender)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.gender)
@Html.ValidationMessageFor(model => model.gender)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.department)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.department)
@Html.ValidationMessageFor(model => model.department)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>