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

grid bulk edit save changes err

1 Answer 33 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Naomi
Top achievements
Rank 1
Naomi asked on 21 Apr 2015, 06:20 AM
hi i am trying to use the grid save changes command.  and i am getting err 500.  it seems to be related to the input of the controller.  but i cant find it.  can any one post an exmple how the controller should look for telerik grid mvc ajax . net 4.5

1 Answer, 1 is accepted

Sort by
0
Naomi
Top achievements
Rank 1
answered on 21 Apr 2015, 06:23 AM
tbis is my code
view: 


   @(Html.Telerik().Grid<ProductTranslatorModel>()
                    .Name("products-grid")
                      .DataKeys(keys =>
                            {
                                keys.Add(p => p.Id);
                            })
                      .ToolBar(commands =>
                                {
                                    commands.SubmitChanges();
                                })
                    .DataBinding(dataBinding => dataBinding.Ajax()
                                    .Select("ProductList", "Translator")
                                    .Update("BulkEditSave", "Translator")
                                    )
                    .Columns(columns =>
                    {
                         columns.Bound(x => x.Id).ReadOnly()
                        .Filterable(false)
                        .ClientTemplate("<input type='checkbox' value='<#= Id #>' class='checkboxGroups'/>")
                        .Title("<input id='mastercheckbox' type='checkbox'/>")
                        .Width(50)
                        .HtmlAttributes(new { style = "text-align:center" })
                        .HeaderHtmlAttributes(new { style = "text-align:center" });
                       if (Model.DisplayProductPictures)
                        {
                            columns.Bound(x => x.PictureThumbnailUrl).ReadOnly()
                                .ClientTemplate("<img alt='<#= Id #>' src='<#= PictureThumbnailUrl #>' />");
                        }
                        columns.Bound(x => x.Name);
                        columns.Bound(x => x.ShortDescription);
                        columns.Bound(x => x.FullDescription);
                        columns.Bound(x => x.LocalShortDescription);
                        columns.Bound(x => x.LocalFullDescription);  
        
                         columns.Command(commands => commands.Delete().Text(T("Admin.Common.Delete").Text)).Title(T("Admin.Common.Delete").Text).Width(50);
                        columns.Bound(x => x.Published).ReadOnly()
                              .ClientTemplate("<img alt='' src='" + Url.Content("~/Administration/Content/images/") + "active-<#= Published #>.gif' />")
                            .Centered()
                            .Width(100);
                    
                    })
                     .Pageable(settings => settings.PageSize(30).Position(GridPagerPosition.Both))
                
                      .Editable(editing => editing.Mode(GridEditMode.InCell))
                     .ClientEvents(events => events.OnDataBinding("onDataBinding").OnDataBound("onDataBound").OnError("Grid_onError").OnSubmitChanges("Grid_onSubmitChanges"))
                     )



controller :


      [AcceptVerbs(HttpVerbs.Post)]
        [HttpPost, GridAction(EnableCustomBinding = true)]
        public ActionResult BulkEditSave(GridCommand command,
            [Bind(Prefix = "updated")]IEnumerable<ProductTranslatorModel> updatedProducts,
            [Bind(Prefix = "deleted")]IEnumerable<ProductTranslatorModel> deletedProducts)
        {
          

            if (updatedProducts != null)
            {
                foreach (var pModel in updatedProducts)
                {
                    //update
                    var product = _productService.GetProductById(pModel.Id);
                    if (product != null)
                    {
                        product.ShortDescription = pModel.ShortDescription;
                        product.FullDescription = pModel.FullDescription;
                        _productService.UpdateProduct(product);
                        UpdateLocalesDescriptaion(product, pModel.LocalShortDescription, pModel.LocalFullDescription);
                    }
                }
            }

            if (deletedProducts != null)
            {
            }
            return RedirectToAction("Configure");
        }
      
Tags
Grid
Asked by
Naomi
Top achievements
Rank 1
Answers by
Naomi
Top achievements
Rank 1
Share this question
or