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

[Solved] Grid will not update

2 Answers 129 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.
Byron
Top achievements
Rank 1
Byron asked on 19 Feb 2013, 02:37 PM
Hello.  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!

2 Answers, 1 is accepted

Sort by
0
Accepted
Ricardo
Top achievements
Rank 1
answered on 21 Feb 2013, 02:17 PM
Hello Byron,

The model class that you are trying to update FeeSrcMstrDteViewModel is not the same on your detail grid,
which is FeeSourceFlatRateCommentsViewModel


On your controller method _UpdateFeeSourceDetailDataAjax, you should do the TryUpdateModel
on the FeeSourceFlatRateCommentsViewModel.


Let me know if it was it.

0
Byron
Top achievements
Rank 1
answered on 21 Feb 2013, 07:25 PM
That was it!  Thanks, Ricardo!
Tags
Grid
Asked by
Byron
Top achievements
Rank 1
Answers by
Ricardo
Top achievements
Rank 1
Byron
Top achievements
Rank 1
Share this question
or