Kendo UI Grid - 内联编辑不会更改为数据库

时间:2012-11-10 01:48:36

标签: asp.net-mvc razor kendo-ui

我正在关注演示网格编辑内联 它可以工作,但不能更改为数据库,它只会更改popolated的列表 我接下来要做什么

这里是代码

public static IList<Book> All()
    {
        IList<Book> result = (IList<Book>)HttpContext.Current.Session["Books"];

        if (result == null)
        {
            HttpContext.Current.Session["Books"] = result =
                (from book in new LibraryModel().Books
                 select new Book
                 {
                     PKiBookID=book.PKiBookID,
                     SBookName = book.SBookName,
                     SBookWriter= book.SBookWriter,
                     SDescription=book.SDescription,
                     BStatus=book.BStatus,
                     FKiBookType=book.FKiBookType

                 }).ToList();
        }

        return result;
    }
    public static Book One(Func<Book, bool> predicate)
    {
        return All().Where(predicate).FirstOrDefault();
    }
    public static void Insert(Book book)
    {
        //book.PKiBookID = All().OrderByDescending(p => p.PKiBookID).First().PKiBookID + 1;
        All().Insert(0,book);
    }
    public static void Update(Book book)
    {
        Book target = One(p => p.PKiBookID == book.PKiBookID);
        if (target != null)
        {
            target.SBookName = book.SBookName;
            target.SBookWriter = book.SBookWriter;
            target.SDescription = book.SDescription;
            target.BStatus = book.BStatus;
            target.BookType = new LibraryModel().BookTypes.Single(s => s.PKiBookTypeID == book.FKiBookType);
        }
    }

1 个答案:

答案 0 :(得分:0)

此例外是quite well known,并且有很多帖子如何避免它。它也包含在Documentation