This is a migrated thread and some comments may be shown as answers.

MVC4 + KendoUI + Grid + popup edit - not updating the database

2 Answers 283 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 23 May 2013, 07:11 PM
Dear Wizards of the Realm,

New to MVC4 and to Kendo. So probably some misconceptions. Tried for a couple days. Need suggestions.

1. Started Visual Studio 2012 new project using Asp.net mvc 4 web app. Connected to existing database with edmx file. Put in a controller. All works great - retrieve, create, update, delete.
2. From Telerik menu, reconfigure to use KendoUI. Using 2012.2.710. (Separate note - if trying to upgrade to 2013.1.x.x - a breaking upgrade). Add an Admin and a Member area - routing seems to be working oK
3. Add Kendo Grid

            @(Html.Kendo().Grid(Model).Name("KeysGrid")
            .Columns(columns =>
            {
                columns.Bound(curkey => curkey.ID).Hidden();
                columns.Bound(curkey => curkey.CreateStamp).Visible(false);
                columns.Bound(curkey => curkey.OwnerAccountsID).Visible(false);
                columns.Bound(curkey => curkey.ReplacedBy).Hidden();
                columns.Bound(curkey => curkey.Name).Width("20%");
                columns.Bound(curkey => curkey.Description).Width("60%");
                columns.Command(cmd =>
                {
                    cmd.Edit().HtmlAttributes(new { title = "edit this key" }).;
                    cmd.Destroy().HtmlAttributes(new { title = "delete this key" });
                })
                    .Width("20%")
                    .Title("Commands")
                    .Width(75);
            })
            .ToolBar(toolBar => toolBar.Template(@"
                <div>
                    <a onclick='createRow()' title='Create a new key' style='float:left;'> <img src='/Content/images/button_add_01.png' style='width:32px; height:32px; text-decoration:none; border:none;' /></a>
                    <a onclick='callHelp()' title='Help on keys' style='float:right;'><img src='/Content/images/button_info_01.png' style='width:32px; height:32px; text-decoration:none; border:none;' /></a>
                </div>
            "))
            .Editable(editable => editable.Mode(GridEditMode.PopUp)
                .TemplateName("AddEditKey").Window(w => w.Title("Add / Edit Keys")))
            .Pageable(pages => pages.PageSizes(new int[] { 10, 20, 50 }))
            .Resizable(p => p.Columns(true))
            .Sortable()
            .Selectable()
            .Filterable()
            .Scrollable(p => p.Enabled(false))
            .Groupable(p => p.Enabled(false))
            .DataSource(datasource => datasource
                .Ajax()
                .Events(e => e.Error("error_handler")
                )
                .Create(c => c.Action("Create", "YFKey", new { area="Member", controller="YFKey", action="Create" }))
                .Update(c => c.Action("Edit", "YFKey", new { area="Member", controller="YFKey", action="Edit" }))
                .Destroy(c => c.Action("Delete", "YFKey", new { area="Member", controller="YFKey", action="Delete" }))
                )
            )
4. Now when go to index page, grid shows data from underlying database. I edit grid, popup comes up with proper fields, edit data, save - popup goes away and changed fields marked with little red triangle - changes to underlying DB not made.
5. In Chrome, hit F12, look at network, it's getting a 500 Internal Server Error. All data from edit form looks proper - just not happening. Any ideas?

Autogenerated controller from database methods include:
        [Authorize]
        public ActionResult Edit(long id = 0)
        {
            YFKey yfkey = db.YFKeys.Find(id);
            if (yfkey == null)
            {
                return HttpNotFound();
            }
            return View(yfkey);
        }

        //
        // POST: /Member/YFKey/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(YFKey yfkey)
        {
            if (ModelState.IsValid)
            {
                db.Entry(yfkey).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(yfkey);
        }

Note that at the same time, the auto created forms from the database first edmx file still work, and even on the same form.

Maybe obvious to me someday, but not today.
Thanks.
Chris

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 24 May 2013, 06:34 AM
Hello,

 The problem is that the Kendo UI Grid for ASP.NET MVC won't work with the auto-generated action methods. We recommend checking the related documentation for implementing ajax editing.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
1
Chris
Top achievements
Rank 1
answered on 27 May 2013, 11:05 PM
OK... I figured it was something obvious.

You know, sometimes it is a REAL PAIN because new versions of everybody's software is coming out all the time... so that even searches on Google are becoming less effective because of all the dependencies that exist in every software solution!

Thanks... that example should do me.

Chris
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or