Edit Not working in MVC contrib grid
i am using mvc contrib grid in that edit is not working so far i have used this coding
in view....
<%= 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 })).Inser开发者_运维问答tAt(1).Encode(false);
})
%>
in my controller i have used :
public ActionResult Edit(int id)
{
ProductsDataContext db = new ProductsDataContext();
return View(db.Products.FirstOrDefault(p => p.CategoryID == id));
}
here details is working in edit is not working
This line should error out:
db.Products.FirstOrDefault(p => p.CategoryID == id)
Multiple Products can have the same CategoryId, so that line will error out when more than 1 Product has the same CategoryId. I don't understand why you are querying Products, but using the CategoryId as the Key.
精彩评论