我似乎無法獲得我的視圖的編輯功能工作..我有一個頁面列出,一個頁面,顯示特定的細節,並在該頁面上,我應該能夠編輯form.PROBLEM的信息:當我運行應用程序時它說:沒有爲此對象定義的無參數構造函數。我究竟做錯了什麼...?MVC 3編輯功能不工作
在主控制器我有:
編輯功能:
[HttpGet]
public ViewResult EditSchoolDetails(int id)
{
var institution = _educationRepository.GetInstititionById(id);
var model = (Mapper.Map<Institution, InstitutionModel>(institution));
return View(model);
}
後 [HttpPost]
public ActionResult EditSchoolDetails(InstitutionModel institutionModel, int id)
{
if (ModelState.IsValid) {
//_get from repository and add to instituion
var institution = _educationRepository.GetInstititionById(institutionModel.Id);
// Map from the view model back to the domain model
var model = Mapper.Map<Institution, InstitutionModel>(institution);
//UpdateModel(model);
SaveChanges();
return RedirectToAction("ViewSchoolDetails", new {institutionModel = institutionModel, id = id});
}
return View(institutionModel);
}
InstitutionModel
public class InstitutionModel {
public InstitutionModel() {
NAABAccreditations = new List<AccreditationModel>();
}
public int Id { get; set; }
public string Name { get; set; }
public bool IsNAAB { get { return NAABAccreditations.Any(); } }
public string Website { get; set; }
public AddressModel Address { get; set; }
public IEnumerable<AccreditationModel> NAABAccreditations { get; set; }
}
viewschool的細節工作,因爲我返回的模型,我已經映射到 – user1179083 2012-08-14 15:13:08
它是否有意義? – user1179083 2012-08-14 15:32:28
不是。拋出的錯誤究竟是什麼時候? – 2012-08-14 15:34:42