我正在尝试编辑记录,但是当视图呈现时,数据没有显示(所有字段都是空的)。我调试了视图模型,我可以看到数据正在正确加载。这是我的代码:编辑操作: public ActionResult Edit(Guid? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var clienteViewModel = GetClienteViewModel(db.Clientes.Find(id)); if (clienteViewModel == null) { return HttpNotFound(); } return View(clienteViewModel); }
1 回答
MYYA
TA贡献1868条经验 获得超4个赞
我发现了错误,我必须包含所有导航
public ActionResult Edit(Guid? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Cliente cliente = db.Clientes.Include(x => x.PessoaFisica).Include(x => x.PessoaFisica.Pessoa).Include(x=> x.PessoaFisica.Pessoa.Endereco).FirstOrDefault(x=>x.Id == id);
if (cliente == null)
{
return HttpNotFound();
}
return View(cliente);
}
- 1 回答
- 0 关注
- 164 浏览
添加回答
举报
0/150
提交
取消