开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜