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

[Solved] Cannot update twice in Grid with Ajax binding

0 Answers 6 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:11 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 { get; set; }
        public string Agency { get; set; }
        public int? Year { get; set; }
        public string FundingType { get; set; }
        [DataType(DataType.Currency)]
        public decimal Amount { get; set; }
    }
}
Tags
Grid
Asked by
Felix Steiny
Top achievements
Rank 1
Share this question
or