Telerik网格未更新

时间:2013-02-20 13:58:09

标签: asp.net-mvc telerik-grid telerik-mvc

我正在尝试使用Ajax绑定创建一个主/详细的Telerik MVC网格。当我选择要更新的详细信息行时,单击“编辑”,编辑该值,然后单击“更新”,该值不会在客户端更新。我在调试器中看到,当我调用TryUpdateModel时,模型没有更新。以下是观点:

@(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()
)

select方法效果很好,但不是更新方法。当我在控制器中调用TryUpdateModel时,我希望模型能够更新,但我没有看到。这是我的控制器代码:

[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));
    }

我错过了什么?谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

我从Telerik网站获得了一些帮助。事实证明,我试图更新不正​​确的模型。我的主网格绑定到FeeSrcMstrDteViewModel,但我要更新的详细网格绑定到FeeSourceFlatRateCommentsViewModel。

修复是在FeeSourceFlatRateCommentsViewModel上调用TryUpdateModel。