모델 레이어로 Entity Framework를 사용하는 MVC3 응용 프로그램이 있습니다. 에는 EmployeeController에서 보기에서 컨트롤러로 MVC3 면도기 모델 전달
, 내가 가진 : EmployeeEdit에서public ActionResult GetEmployeeEdit(String id)
{
// Get the desired Employee
var model = GetEmployees().FirstOrDefault(o=>o.EFolderid == id);
return View("EmployeeEdit", model);
}
private IQueryable<Employee> GetEmployees()
{
// Returns IQueryable<Employee>
return _employeeService.GetTable();
}
내가 가진 :
@model Metastorm.Domain.Models.Employee
@{
ViewBag.Title = "Employee Edit";
}
@using (Html.BeginForm("SaveEmployee", "Employee", FormMethod.Get, Model))
{
<fieldset>
<legend>Edit Employee</legend>
<br />
@Html.Label("firstName", "First Name: ")
@Html.EditorFor(o => @Model.NameFirst)
<br />
@Html.Label("lastName", "Last Name: ")
@Html.EditorFor(o => @Model.NameLast)
</fieldset>
<br />
<input class="button" id="submit" type="submit" value = "Save Employee" />
}
을 이제 다시에는 EmployeeController에 :
[HttpGet]
public ActionResult SaveEmployee(Employee employee)
{
if (ModelState.IsValid)
{
// Get the Employee Model again from Entity, Update and save
// Unfortunately, the employee object's FolderId value is null
}
// Just getting a model to satisfy the function
var model = GetEmployees().FirstOrDefault();
return View("EmployeeEdit", model);
}
을 나는 데 문제가 Employee.NameFirst 및 Employee.NameLas를 제외하고 employee 객체의 모든 속성이 null임을 나타냅니다. t, 이는 View with Html.EditorFor에서 노출 된 속성입니다.
요약하면 필자는 수화 된 Employee 모델 객체를 얻습니다. 컨트롤러에서 뷰로이 모델을 전달합니다. 보기에서 선택한 필드는 업데이트 할 수 있습니다. 그런 다음 Employee 모델은 업데이트가 유지되는 컨트롤러로 다시 전달됩니다.
제 질문은 원래 Controller에서 View로 원래 전달 된 Employee 모델을 그대로 유지하는 것입니다. 즉, 모델을 갖고 싶습니다