0
votes

I am trying to create a master/detail Telerik MVC grid with Ajax binding. When I select a detail row to update, click "Edit", edit the value, then click "Update", the value is not updated on the client side. I see in the debugger that the model is not updated when I call TryUpdateModel. Here is the view:

@(Html.Telerik().Grid<FeeSrcMstrDteViewModel>()
.Name("FeeSourceConfirmMasterGrid")
.Columns(columns =>
    {
        columns.Bound(m => m.FEE_SRC_NME).Width(65).Title(@FeeBuilderResource.FeeSourceName);
        columns.Bound(m => m.PUBLISHING_ENTITY_NME).Width(45).Title(@FeeBuilderResource.PublishingEntity);
        columns.Bound(m => m.FEE_SRC_SRVC_CATEGORY_NME).Width(55).Title(@FeeBuilderResource.ServiceTypeCategory);
        columns.Bound(m => m.FEE_SRC_PUBLISHED_DTE).Width(45).Title(@FeeBuilderResource.PublishedDate).Format("{0:d}");
        columns.Bound(m => m.YEAR).Width(30).Title(@FeeBuilderResource.Year);
        if (Model.FeeSourceMasterDate.GEO_LOC_ID == 1 || Model.FeeSourceMasterDate.GEO_LOC_ID == 4)
        {
            columns.Bound(m => m.STATE).Width(50).Title("State or carrier locality");
        }
        else
        {
            columns.Bound(m => m.CARRLOC).Width(50).Title("State or carrier locality");
        }
        //columns.Command(commands => commands.Custom("ExportToExcel").Text("Export to Excel")
            //.DataRouteValues(route => route.Add(m => m.FeeSourceMasterDate.FEE_SRC_MSTR_ID).RouteKey("FEE_SRC_MSTR_ID"))
            //.Ajax(false).Action("_ConfirmMasterExportXlsAjax", "FeeSrcFlatRate", new { feeSourceServiceMasterDateId = "<#= FEE_SRC_MSTR_ID #>" }))
            //.HtmlAttributes(new { style = "text-align: center" }).Width(50).Title(@FeeBuilderResource.Actions);
    })
    //.ClientEvents(events => events.OnSave("FeeSourceTestGrid_OnSave"))
    .DetailView(details => details.ClientTemplate(
        Html.Telerik().Grid<FeeSourceFlatRateCommentsViewModel>()
        .Name("FeeSourceHome_<#= FEE_SRC_MSTR_ID #>")
        .DataKeys(keys => keys.Add(m => m.CommentId))
        .DataBinding(dataBinding => dataBinding.Ajax()
            .Select("_GetFeeSourceDetailDataAjax", "FeeSrcFlatRate")
            .Update("_UpdateFeeSourceDetailDataAjax", "FeeSrcFlatRate")
            )
        .Columns(columns =>
        {
            columns.Bound(m => m.CommentId).Width(200).Hidden();
            columns.Bound(m => m.FeeSourceDescription).Width(200).Title("Fee source description");
            columns.Bound(m => m.FeeSourceComments).Width(200).Title("Fee source comments");
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.ImageAndText);
            }).Width(75);

        })
        .DataBinding(dataBinding => dataBinding.Ajax()
            .Select("_GetFeeSourceDetailDataAjax", "FeeSrcFlatRate", new { id = "<#= FEE_SRC_DTE_ID #>" }))
            .Editable(editing => editing.Mode(GridEditMode.InLine).InsertRowPosition(GridInsertRowPosition.Top))
            .Footer(false)
            .ToHtmlString()
            ))
.DataBinding(dataBinding => dataBinding.Ajax()
    .Select("_GetFeeSourceDataAjax", "FeeSrcFlatRate"))
    .Pageable(paging => paging.PageSize(20))
    //.Scrollable(scrolling => scrolling.Height(580))
    .Sortable()
)

The select methods work great, but not the update method. I would expect the model to be updated when i call TryUpdateModel in my controller, but I do not see that. Here is my controller code:

[HttpPost]
[GridAction]
public ActionResult _UpdateFeeSourceDetailDataAjax(int id)
{
    FeeSourceFlatRateViewModel modelTest = new FeeSourceFlatRateViewModel();           

    List<FeeSourceFlatRateCommentsViewModel> commentsList = new 

List<FeeSourceFlatRateCommentsViewModel>();

        // get the model by id
        IFeeSourceMstrRepository repo = new FeeSourceMstrRepository();

        IList<FeeSrcMstrDteViewModel> modelTestList = repo.GetFeeSrcMstrDteViewModel((int)id);
        FeeSrcMstrDteViewModel modelTestChange = modelTestList[0];

        //Perform model binding (fill the product properties and validate it).
        if (TryUpdateModel(modelTestChange))
        {
            var testy = modelTestChange;

            // set the comments
            FeeSourceFlatRateCommentsViewModel modelComments = new FeeSourceFlatRateCommentsViewModel
            {
                CommentId = id,
                FeeSourceDescription = modelTestChange.FEE_SRC_DESC,
                FeeSourceComments = modelTestChange.FEE_SRC_COMMENTS
            };

            commentsList.Add(modelTestChange);

            // save the object
            repo.SaveFeeSrcUOW(saveModel);
            OperationStatus opStatus = repo.Save();

        }

        TempData["FeeSourceFlatRateModel"] = modelTestChange;
        return View(new GridModel(commentsList));
    }

What am I missing? Thanks for the help!

1

1 Answers

0
votes

I got some help from the Telerik site. As it turns out, I was trying to update the incorrect model. My master grid is bound to FeeSrcMstrDteViewModel, but my detail grid, which I want to update, is bound to FeeSourceFlatRateCommentsViewModel.

The fix was to call TryUpdateModel on the FeeSourceFlatRateCommentsViewModel.