This question is locked. New answers and comments are not allowed.
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
ViewModel
Controller
Any ideas what could be wrong? Thanks very much for any help.
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.