Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7787805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:47:18+00:00 2026-06-01T20:47:18+00:00

I’ve implemented an MVC3/Razor Grid Control from the Editing Batch example in the Telerik

  • 0

I’ve implemented an MVC3/Razor Grid Control from the Editing Batch example in the Telerik Extensions for ASP.NET MVC (Telerik Sample) and for the most part, I think it’s working, however I have noticed that while the updates appear to be working on the client, the underlying database tables are not updated.

I thought that I may have missed some step in my implementation of this, however after doing an update in the Batch Editing example for a Product Name in the Telerik Example that I downloaded using the Northwind database, the underlying data tables also is not changed.

VIEW:

@model IEnumerable<MarketingWebsiteTools.Models.EditableCallout>

@using MarketingWebsiteTools.Extensions;
@using MarketingWebsiteTools.Models;

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Marketing Messages</h2>


@(Html.Telerik().Grid<MarketingWebsiteTools.Models.EditableCallout>()
    .Name("Grid")
            .DataKeys(keys =>
            {
                keys.Add(p => p.id);
            })
        .ToolBar(commands =>
        {
            commands.Insert();
            commands.SubmitChanges();
        })
    .Columns(columns =>
    {

        columns.Bound(o => o.ProductIdentifier).Width(125);
        columns.Bound(o => o.DateStart).Width(75);
        columns.Bound(o => o.DateEnd).Width(75);
        columns.Bound(o => o.Value).Width(75);
        columns.Bound(o => o.IsActive).Width(75);
        columns.Command(commands => commands.Delete()).Width(125).Title("Delete");
    })
                .ClientEvents(events => events.OnDataBinding("Grid_onDataBinding").OnError("Grid_onError"))
                .Editable(editing => editing.Mode(GridEditMode.InCell).DefaultDataItem(new EditableCallout
                {
                    DateStart = DateTime.Today

                }))
            .DataBinding(dataBinding => dataBinding.Ajax()
            .Select("_Index", "Callouts")
            .Update("_SaveBatchEditing", "Callouts")
            )

            .Pageable()
            .Scrollable()
            .Sortable()
            .Groupable()
            .Filterable()
)

<script type="text/javascript">
    function Grid_onError(args) {
        if (args.textStatus == "modelstateerror" && args.modelState) {
            var message = "Errors:\n";
            $.each(args.modelState, function (key, value) {
                if ('errors' in value) {
                    $.each(value.errors, function () {
                        message += this + "\n";
                    });
                }
            });
            args.preventDefault();
            alert(message);
        }
    }
    function Grid_onDataBinding(e) {
        var grid = $(this).data('tGrid');
        if (grid.hasChanges()) {
            if (!confirm('You are going to lose any unsaved changes. Are you sure?')) {
                e.preventDefault();
            }
        }
    }
</script>


@section HeadContent {
<style type="text/css">
    .field-validation-error
    {
        position: absolute;
        display: block;
    }

    * html .field-validation-error { position: relative; }
    *+html .field-validation-error { position: relative; }

    .field-validation-error span
    {
        position: absolute;
        white-space: nowrap;
        color: red;
        padding: 17px 5px 3px;
        background: transparent url('@Url.Content("~/Content/Common/validation-error-message.png") ') no-repeat 0 0;
    }

    /* in-form editing */
    .t-edit-form-container
    {
        width: 350px;
        margin: 1em;
    }

    .t-edit-form-container .editor-label,
    .t-edit-form-container .editor-field
    {
        padding-bottom: 1em;
        float: left;
    }

    .t-edit-form-container .editor-label
    {
        width: 30%;
        text-align: right;
        padding-right: 3%;
        clear: left;
    }

    .t-edit-form-container .editor-field
    {
        width: 60%;
    }
</style>
} 

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 PagedList;
using Telerik.Web.Mvc;
using MarketingWebsiteTools.Models;
using MarketingWebsiteTools.ViewModels;
//using MarketingWebsiteTools.Services;
using MarketingWebsiteTools.Filters;

namespace MarketingWebsiteTools.Controllers
{ 
    public partial class CalloutsController : Controller
    {
        [SourceCodeFile("EditableCallout", "~/Models/EditableCallout.cs", Order=1 )]
        [SourceCodeFile("SessionCalloutRepository", "~/Models/SessionCalloutRepository.cs", Order = 2)]
        [SourceCodeFile("SessionCalloutRepository", "~/Models/SessionCalloutRepository.cs", Order = 3)]

        public ActionResult Index()
        {
            return View();
        }

        [GridAction]
        public ActionResult _Index()
        {
            return View(new GridModel(SessionCalloutRepository.All()));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [CultureAwareAction]
        [GridAction]
        public ActionResult _SaveBatchEditing([Bind(Prefix =
            "inserted")]IEnumerable<EditableCallout> insertedCallouts,
            [Bind(Prefix = "updated")]IEnumerable<EditableCallout> updatedCallouts,
            [Bind(Prefix = "deleted")]IEnumerable<EditableCallout> deletedCallouts)
        {
            if (insertedCallouts != null)
            {
                foreach (var callouts in insertedCallouts)
                {
                    SessionCalloutRepository.Insert(callouts);
                }
            }
            if (updatedCallouts != null)
            {
                foreach (var callouts in updatedCallouts)
                {

                    var target = SessionCalloutRepository.One(p => p.id == callouts.id);
                    if (target != null)
                    {
                        target.DateStart = callouts.DateStart;
                        target.DateEnd = callouts.DateEnd;
                        target.Value = callouts.Value;
                        target.IsActive = callouts.IsActive;
                        SessionCalloutRepository.Update(target);
                    }
                }
            }
            if (deletedCallouts != null)
            {
                foreach (var product in deletedCallouts)
                {
                    SessionCalloutRepository.Delete(product);
                }
            }
            return View(new GridModel(SessionCalloutRepository.All()));
        }
    }
}

MODEL:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;

namespace MarketingWebsiteTools.Models
{
    //[KnownType(typeof(EditableCallout))]
    public class EditableCallout
    {
        //[ScaffoldColumn(false)]
        [DisplayName("id")]
        public int id { get; set; }
        [Required]
        [DisplayName("ProductIdentifier")]
        public string ProductIdentifier { get; set; }

        [DisplayName("DateStart")]
        public DateTime? DateStart { get; set; }

        [DisplayName("DateEnd")]
        public DateTime? DateEnd { get; set; }

        [DisplayName("IsActive")]
        public int? IsActive { get; set; }

        [DisplayName("Value")]
        public string Value { get; set; }
    }
}

REPOSITORY:

namespace MarketingWebsiteTools.Models
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using MarketingWebsiteTools.ViewModels;
    using MarketingWebsiteTools.Models;

    public static class SessionCalloutRepository
    {
        public static IList<EditableCallout> All()
        {
            WebsiteDataContext wdc = new WebsiteDataContext();
            //CalloutContext db = new CalloutContext();
            IList<EditableCallout> result = (IList<EditableCallout>)HttpContext.Current.Session["Callouts"];

            if (result == null)
            {
                HttpContext.Current.Session["Callouts"] = result =
                   (from c in wdc.CalloutToProducts
                    join cv in wdc.CalloutValues on c.CalloutID equals cv.CalloutID
                    select new EditableCallout
                    {
                        id = c.id,
                        ProductIdentifier = c.ProductIdentifier,
                        DateStart = c.DateStart,
                        DateEnd = c.DateEnd,
                        Value = cv.Value,
                        IsActive = c.IsActive
                    }).ToList();
            }

            return result;
        }


        public static EditableCallout One(Func<EditableCallout, bool> predicate)
        {
            return All().Where(predicate).FirstOrDefault();
        }
        public static void Insert(EditableCallout callout)
        {
            callout.id = All().OrderByDescending(c => c.id).First().id+ 1;
            All().Insert(0, callout);
        }

        public static void Update(EditableCallout callout)
        {
            EditableCallout target = One(c => c.id == callout.id);
            if (target != null)
            {
                target.ProductIdentifier = callout.ProductIdentifier;
                target.DateEnd = callout.DateEnd;
                target.DateStart = callout.DateStart;
                target.Value = callout.Value;
                target.IsActive = callout.IsActive;

            }
        }
        public static void Delete(EditableCallout callout)
        {
            EditableCallout target = One(c => c.id== callout.id);
            if (target != null)
            {
                All().Remove(target);
            }
        }
    }
}

Thanks

Doug

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:47:19+00:00Added an answer on June 1, 2026 at 8:47 pm

    The Telerik demos are intentionally not updating the underlying data base. All changes are kept in-memory (in Session). You need to add the required code which will update the data base.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.