This question is locked. New answers and comments are not allowed.
I have a simple grid with two colums, Name and Value. The items are stored in a simple object with two properties as follows:
The objects are stored in a Dictionary<string, NameValuePairModel> object, which is persisted to session state.
When I insert the first item it works fine. Inserting the second item results in an exception from trying to insert a duplicate record into the dictionary. Tracing through the code, I find that the InsertParameter method is being called once for each row in the grid instead of just for the row that's being added.
The controller code is as follows:
And the grid code in the view is as follows:
I can't figure out why it's doing this. The demo doesn't seem to do this, but for some reason every time I try to use the data bound editing with the grid my code does it.
Any assistance would be appreciated.
I can code around it by checking to see if the collection already contains the key, but that's a bit kludgy and I'd prefer not to.
Thanks!
Morgan
[Serializable]public class NameValuePairModel{ private string name; private string value; public string Name { get {return name;} set {name = value;} } public string Value { get {return value;} set {this.value = value;} }}The objects are stored in a Dictionary<string, NameValuePairModel> object, which is persisted to session state.
When I insert the first item it works fine. Inserting the second item results in an exception from trying to insert a duplicate record into the dictionary. Tracing through the code, I find that the InsertParameter method is being called once for each row in the grid instead of just for the row that's being added.
The controller code is as follows:
[GridAction]public ActionResult InsertParameter(){ Dictionary<string, NameValuePairModel> parameters = GetParametersFromSession(); NameValuePairModel model = new NameValuePairModel(); if (TryUpdateModel(model)) { parameters.Add(model.Name, model); Session["testParameters"] = parameters; } return View(new GridModel<NameValuePairModel> { Data = GetParameterGridData(parameters) });}And the grid code in the view is as follows:
<div class="sizedContainer" style="height: 240px; background-color: #696969"> @(Html.Telerik().Grid<NameValuePairModel>() .Name("Rulesets") .DataKeys(keys => keys.Add(p => p.Name)) .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text)) .Columns(columns => { columns.Bound(o => o.Name).Title("Name").Filterable(false).Sortable(true); columns.Bound(o => o.Value).Title("Value").Filterable(false).Sortable(true); columns.Command(commands => { commands.Edit().ButtonType(GridButtonType.Image); commands.Delete().ButtonType(GridButtonType.Image); }); }) .DataBinding( dataBinding => dataBinding.Ajax().OperationMode(GridOperationMode.Server) .Select("GetParameters", "TestHarness") .Insert("InsertParameter", "TestHarness") .Delete("DeleteParameter", "TestHarness") .Update("UpdateParameter", "TestHarness")) .Sortable() .Editable(editing => editing.Mode(GridEditMode.InLine)) .Pageable( paging => paging.PageSize(5) .Style(GridPagerStyles.NextPreviousAndNumeric | GridPagerStyles.PageSizeDropDown) .Position(GridPagerPosition.Both) )) I can't figure out why it's doing this. The demo doesn't seem to do this, but for some reason every time I try to use the data bound editing with the grid my code does it.
Any assistance would be appreciated.
I can code around it by checking to see if the collection already contains the key, but that's a bit kludgy and I'd prefer not to.
Thanks!
Morgan