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

[Solved] Cannot update twice in Grid with Ajax binding

1 Answer 16 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Felix Steiny
Top achievements
Rank 1
Felix Steiny asked on 17 Apr 2012, 03:17 AM
I am having trouble with a project in a grid with Ajax binding.  The grid seems to work fine for Insert, Update, Delete, Select.  However, once I have performed one Update operation, I cannot perform another Update operation in the same grid until I refresh the page.  Attempting to click the Update button the second time throws a javascript error:
Uncaught TypeError: Cannot read property 'Id' of undefined 

I created a test project to strip away all the layers of complexity to try to find the issue.  Even at the simplest level, with no real data interactions, I am getting the same error.  What am I doing wrong?

The View:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="MvcTestApp.Models" %>
<%@ Import Namespace="Telerik.Web.Mvc.UI" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
      
        <%= Html.Telerik().Grid<PreviousFunding>()
               .Name("PreviousFundingGrid")
               .DataKeys(keys => keys.Add(k => k.Id))
               .Columns(cols =>
                            {
                                cols.Bound(c => c.Agency).Title("Agency/Funder");
                                cols.Bound(c => c.Year);
                                cols.Bound(c => c.FundingType).Title("Description");
                                cols.Bound(c => c.Amount)
                                    .Aggregate(a => a.Sum())
                                    .ClientFooterTemplate("Total: $<#= Sum #>");
                                 cols.Command(com =>
                                                  {
                                                      com.Edit();
                                                      com.Delete();
                                                  }).Title("Commands");
                             })
               .DataBinding(db => db.Ajax()
                                .Select("Select", "PreviousFunding")
                                .Insert("Insert", "PreviousFunding")
                                .Update("Update", "PreviousFunding")
                                .Delete("Delete", "PreviousFunding"))
               .ToolBar(commands => commands.Insert())
               .Editable(editing => editing.Mode(GridEditMode.InLine))
               .Sortable()
        %>
 
</asp:Content>

The Controller:
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using MvcTestApp.Models;
using Telerik.Web.Mvc;
 
namespace MvcTestApp.Controllers
{
    public class PreviousFundingController : Controller
    {
        [GridAction]
        public ActionResult Select()
        {
            var items = new List<PreviousFunding>
                           {
                               new PreviousFunding
                                   {
                                       Agency = "Agent 1",
                                       Amount = 20000,
                                       FundingType = "Super Funding",
                                       Id = new Guid("B12391EB-CD24-4766-8BF4-84450C3FD392"),
                                       Year = 1999
                                   },
                               new PreviousFunding
                                   {
                                       Agency = "Agent B",
                                       Amount = 9600,
                                       FundingType = "Super Funding",
                                       Id = new Guid("C21F6EC3-8138-4909-8DD9-0E2CEBAE01E7"),
                                       Year = 2000
                                   }
                           };
 
            return View(new GridModel(items));
        }
 
        [GridAction]
        public ActionResult Update(PreviousFunding item)
        {
            return Select();
        }
 
        [GridAction]
        public ActionResult Insert(PreviousFunding item)
        {
            return Select();
        }
 
        [GridAction]
        public ActionResult Delete(PreviousFunding item)
        {
            return Select();
        }
 
    }
}

The Model:
using System;
using System.ComponentModel.DataAnnotations;
 
namespace MvcTestApp.Models
{
    public class PreviousFunding
    {
        public Guid Id { getset; }
        public string Agency { getset; }
        public int? Year { getset; }
        public string FundingType { getset; }
        [DataType(DataType.Currency)]
        public decimal Amount { getset; }
    }
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 17 Apr 2012, 10:17 AM
Hello Felix,

Thank you for attaching a sample project. I assume that the scripts version you are using is different than the version of the assembly (I saw that you are using Themes from version Q1 2012). Replace the scripts to use the version 2011.3.1115 and everything should be working fine.

Kind regards,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Felix Steiny
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or