This question is locked. New answers and comments are not allowed.
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)); } } }