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

[Solved] Ajax update posting incrementally

3 Answers 87 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.
Travis
Top achievements
Rank 1
Travis asked on 26 Jul 2011, 12:54 AM

I have a grid using Q2 2011 version of telerik's MVC controls that is using ajax binding/updating.  The grid will update without errors the first time, but the second time it will make an additional ajax call to update the record.  The first call will not include the data key parameter at all and so will fail with an error.  The last call does include the data key and value and updates the record fine.  The number of invalid calls increments by one each time you update a record.  If I change the grid's editmode to GidEditMode.PopUp, the problem does not occur.  Any ideas why this is happening?

Here's the View:

@model IEnumerable<FoodReviewsDAL.Review>
  
@{
    ViewBag.Title = "Index";
}
  
<h2>Index</h2>
  
@(Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataKeys(keys => keys.Add(p => p.RestaurantReviewID).RouteKey("RestaurantReviewID"))
        .ToolBar(commands => commands.Insert())
        .Columns(columns => 
        {
            columns.Bound(o => o.DateReviewed)
                .Width(75);
            columns.Bound(o => o.Description);
            columns.Bound(o => o.Rating);
            columns.Command(commands => { commands.Edit(); commands.Delete(); }).Width(200);
        })
        .DataBinding(dataBinding => dataBinding.Ajax()
            .Select("_SelectAjaxEditing", "Reviews")
            .Insert("_InsertAjaxEditing", "Reviews")
            .Update("_SaveAjaxEditing", "Reviews")
            .Delete("_DeleteAjaxEditing", "Reviews"))
        .Pageable()
        .Sortable()
        .Editable(editing => editing.Mode(GridEditMode.InLine))
        )
 

Here's the controller:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FoodReviewsDAL;
using Telerik.Web.Mvc;
  
namespace FoodReviewsMF.Controllers
    public class ReviewsController : Controller
    {
        private FoodReviewEntities db = new FoodReviewEntities();
  
        //
        // GET: /Reviews/
  
        public ViewResult Index()
        {
            return View();
        }
  
        [GridAction]
        public ActionResult _SelectAjaxEditing()
        {
            return View(new GridModel(db.Reviews));
        }
  
        [GridAction]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult _SaveAjaxEditing(int RestaurantReviewID)
        {
                //Doesn't seem to matter whether we save anything or not, so commented this out
            //Review r = db.Reviews.Find(RestaurantReviewID);
            //TryUpdateModel(r);
            //db.SaveChanges();
            return View(new GridModel(db.Reviews));
        }
  
        [GridAction]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult _InsertAjaxEditing(Review r)
        {
            db.Reviews.Add(r);
            db.SaveChanges();
            return View(new GridModel(db.Reviews));
        }
  
        [GridAction]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult _DeleteAjaxEditing(int RestaurantReviewID)
        {
            Review r = db.Reviews.Find(RestaurantReviewID);
            db.Reviews.Remove(r);
            db.SaveChanges();
            return View(new GridModel(db.Reviews));
        }
  
    }
}


 

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 26 Jul 2011, 09:45 AM
Hello Travis,

Unfortunately, I'm not able to recreate such behavior locally. Therefore, it will be appreciated if you could send us a small runnable project in which this issue can be observed locally.

Regards,
Rosen
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Travis
Top achievements
Rank 1
answered on 26 Jul 2011, 04:06 PM
Looks like it was my version of jquery.  jquery-1.6.2.min.js was causing this problem, but jquery-1.5.1.min.js did not.
0
Rosen
Telerik team
answered on 26 Jul 2011, 05:40 PM
Hello Travis,

Indeed, we have recently located a similar issue related to editing functionality  when jQuery 1.6.x is included. Please refer to this forum thread for an internal build to try.

Greetings,
Rosen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Tags
Grid
Asked by
Travis
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Travis
Top achievements
Rank 1
Share this question
or