我正在使用mvc contrib grid,因为编辑到目前为止我还没有使用这个编码
在视野中......
<%= Html.Grid<Product>(Model)
.Columns(column =>
{
column.For(c => c.CategoryID);
column.For(c => c.SupplierID);
column.For(c => c.ProductID);
column.For(c => Html.ActionLink("Details", "Details", new { id = c.CategoryID })).InsertAt(0).Encode(false);
column.For(c => Html.ActionLink("Edit", "Edit", new { id = c.CategoryID })).InsertAt(1).Encode(false);
})
%>
在我使用的控制器中:
public ActionResult Edit(int id)
{
ProductsDataContext db = new ProductsDataContext();
return View(db.Products.FirstOrDefault(p => p.CategoryID == id));
}
此处详细信息正在编辑中无法正常工作
答案 0 :(得分:0)
这一行应该出错:
db.Products.FirstOrDefault(p => p.CategoryID == id)
多个产品可以具有相同的CategoryId,因此当多个产品具有相同的CategoryId时,该行将会出错。我不明白你为什么要查询产品,但是使用CategoryId作为密钥。