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

[Solved] Problem with delete commands breaking data binding when deploying website

6 Answers 41 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.
Jeff
Top achievements
Rank 1
Jeff asked on 16 Sep 2011, 08:39 PM
Hello all.  I've been working with Telerik's radgrid control in Visual Studio 2010 with Microsoft MVC 3 for a few months, and we're deploying our first grid using application this month.  Unfortunatly, when I went from my local environment to a live environment, I ran into a number of issues with data binding.  In most cases, I just needed to add a column containing the property in question in a hidden field to the grid and my ViewModel would bind to the property normally.  However, in the case of the delete command, the confirmation prompt seems to be breaking all of my data binding before the command executes, resulting in a 0 ID value being passed into the controller, which causes a 500 error if I don't catch the 0.  Here is the relevant code, nothing fancy.

View
@(Html.Telerik().Grid<Namespace.ViewModels.TypeViewModel>()
            .Name("TypeGrid")
            .DataKeys(keys =>
            {
                keys.Add(sp => sp.TypeID );
            })
            .ToolBar(commands =>
            {
                commands.Insert().ButtonType(GridButtonType.ImageAndText);
  
            })
            .DataBinding(dataBinding =>
            {
                dataBinding.Ajax()
                    .Select("_TypeSelect", "Maintenance")
                    .Update("_TypeUpdate", "Maintenance")
                    .Insert("_TypeInsert", "Maintenance")
                    .Delete("_TypeDelete", "Maintenance");
            })
              
            .Columns(columns =>
            {
                columns.Command(commands => { commands.Edit().ButtonType(GridButtonType.Image); }).Title("Edit").Width(50);
                columns.Command(commands => { commands.Delete().ButtonType(GridButtonType.Image); }).Title("Delete").Width(50);
                columns.Bound(sp => sp.TypeDescription);
                columns.Bound(sp => sp.TypeID).Hidden(true);
                columns.Bound(sp => sp.IsActive).Hidden(true);
            })
            .Editable(editing => editing.Mode(GridEditMode.InLine))
            .Pageable(paging => paging.Enabled(true).Style(GridPagerStyles.NextPrevious | GridPagerStyles.Numeric | GridPagerStyles.PageSizeDropDown | GridPagerStyles.Status))
            .Sortable()
        )

ViewModel
public class TypeViewModel
    {
        [DisplayName("Type ID")]
        public int TypeID { get; set; }
  
        [Required]
        [DisplayName("Description")]
        public string TypeDescription { get; set; }
  
        public bool IsActive { get; set; }
    }

Controller
[OutputCache(CacheProfile = "ZeroCache")]
        [GridAction]
        public ActionResult _TypeDelete(TypeViewModel viewModel)
        {
            //delete the object
            if (viewModel.TypeID != 0)
            {
                Type aType = Mapper.Map<TypeViewModel, Type>(viewModel);
                _maintRepo.TypeDelete(aType);
            }
  
            //refresh the grid
            var result = _maintRepo.GetTypes();
            IEnumerable<TypeViewModel> updatedModel = Mapper.Map<IEnumerable<Type>, IEnumerable<TypeViewModel>>(result);
            return View(new GridModel(updatedModel));
        }

Any ideas what could be wrong?  Thanks very much for any help.

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 19 Sep 2011, 09:34 AM
Hello Jeff,

 By default the grid submits the data key as "id". You can use the RouteKey setting to make the grid submit the data key as a different route value. Perhaps this would populate the model correctly:

keys.Add(sp => sp.TypeID).RouteKey("TypeID");

Regards,

Atanas Korchev
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
0
Jeff
Top achievements
Rank 1
answered on 19 Sep 2011, 02:45 PM
Hi Atanas, thanks for the help.  Unfortunately, this doesn't seem to be solving my problem.  Do you have any other ideas for things I should look into?
0
Atanas Korchev
Telerik team
answered on 19 Sep 2011, 02:48 PM
Hi Jeff,

 This is strange. Could you check if the TypeID is posted to the server when deleting a row? You can use FireBug or IE dev toolbar to inspect the HTTP request generated by the delete command.

Best wishes,
Atanas Korchev
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
0
Jeff
Top achievements
Rank 1
answered on 19 Sep 2011, 03:52 PM
I normally use Firebug, but for this application I have to use IE and I'm not very familiar with the IE dev tools.  Where in the dev tools interface do I need to look to find the HTTP request that my command is generating?  Thanks again for your time.
0
Atanas Korchev
Telerik team
answered on 19 Sep 2011, 03:55 PM
Hi Jeff,

 IE developer toolbar is accessible after pressing F12. Network traffic is available only in IE9 though. By the way you can just use FireFox to try this. The problem would appear there as well.

Regards,
Atanas Korchev
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
0
Jeff
Top achievements
Rank 1
answered on 19 Sep 2011, 05:27 PM
Thanks for the help Atanas.  I installed Fiddler to track my requests, and your first solution actually worked.  The TypeID was actually getting passed in correctly after I added the RouteKey parameter.  The exception I was seeing after adding it was caused by the TypeDescription parameter binding being broken in the same manner by the delete prompt.  I added a second entry to the data keys function and used the RouteKey function to bind my TypeDescription as well and everything worked great.  Thanks again for your time.
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or