【发布时间】:2011-04-18 17:38:09
【问题描述】:
我使用 ASP.NET MVC3 作为数据层 LinqToSql。 我有点困惑如何编辑实体。
public ActionResult Edit(int id)
{
var product = _repository.GetById(id);
return View(product);
}
[HttpPost]
public ActionResult Edit(Product product)
{
if (ModelState.IsValid)
{
_repository.EditProduct(product);
return RedirectToAction("Index");
}
return View();
}
Edit() 中的变量乘积是可以的,但是在编辑视图之后在 [HttpPost] Edit 中传入的变量 在链接属性中有 null 并且似乎与我的 DataContext 分离。 还有我应该在 EditProduct 方法中执行什么代码来更新实体?
谢谢。
【问题讨论】:
标签: asp.net-mvc linq-to-sql asp.net-mvc-3 datacontext