我的剑道网格正在复制记录 [英] My kendo grid is duplicating records

查看:77
本文介绍了我的剑道网格正在复制记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个剑道gri.

I have a kendo gri in my application.

这是一张照片.

这是代码

@(Html.Kendo().Grid<TekstenViewModel.Tekst>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Template(@<text></text>).ClientTemplate("<input type='checkbox'/>").Width(10).Hidden(!Model.Administrator);

        columns.Bound(product => product.RESOURCE_SET_NAAM).ClientTemplate("#= RESOURCE_SET_NAAM#");

        columns.Bound(product => product.Naam).ClientTemplate("#= Naam#");

        columns.Bound(product => product.Waarde).ClientTemplate("<div id='editorDiv'><div class='input'>#if(Waarde){# #if(Waarde.length>100){# # var myContent =Waarde; #  # var dcontent = myContent.substring(0,100); # <span>#=kendo.toString(dcontent)#</span> #}else{# <span>#=Waarde#</span> #}# #}#</div><div class='editor'>" +
            Html.WebCore().LinkButton(type: ButtonType.Edit, htmlAttributes: new { onclick = "openPopupDemo('#: Waarde #', '#: ID #', 'Waarde')" }));

        columns.Bound(product => product.Opmerking).ClientTemplate("<div id='editorDiv'><div class='input'>#if(Opmerking){# #if(Opmerking.length>100){# # var myContent =Opmerking; #  # var dcontent = myContent.substring(0,100); # <span>#=kendo.toString(dcontent)#</span> #}else{# <span>#=Opmerking#</span> #}# #}#</div><div class='editor'>" +
            Html.WebCore().LinkButton(type: ButtonType.Edit, htmlAttributes: new { onclick = "openPopupDemo('#: Opmerking #', '#: ID #', 'Opmerking')" }));

        columns.Template(@<text></text>).ClientTemplate("<div id='deleteDiv'><div class='delete'><a class=\"delete iconBtn\" onclick=\"deleteResourceItem(#: ID #, '#: Naam #')\"></a></div></div>").Width(10).Hidden(!Model.Administrator);
    })
    .Pageable()
    .Sortable()
    .Filterable()
        .Events(events => events.Edit("onCellEdit").DataBinding("onDataBinding").DataBound("onDataBound"))
    .Groupable()
    .Resizable(a => a.Columns(true))
    .Navigatable()
    .Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .Events(e => e.Error("error_handler"))
        .Model(model =>
        {
            model.Id(product => product.ID);
            model.Field(product => product.Naam).Editable(Model.Administrator);
            model.Field(product => product.Opmerking).Editable(Model.Administrator);
            model.Field(product => product.Waarde).Editable(!Model.ReadOnly);
            model.Field(product => product.RESOURCE_SET_ID).DefaultValue(Model.SetID);
            model.Field(product => product.Type).DefaultValue(Domain.Agromilieu2.Common.Objects.Entities.Resources.ResourceType.GLOBAL_RESOURCES);
            model.Field(product => product.Taal).DefaultValue(Domain.Agromilieu2.Common.Agromilieu2Constants.Resources.DEFAULT_TAAL_CODE);
        })
        .Create(create => create.Action(MVC.BeheerTeksten.ActionNames.ResourceItems_Create, MVC.BeheerTeksten.Name).Data("onCreateAdditionalData"))
        .Read(read => read.Action(MVC.BeheerTeksten.ActionNames.ResourceItems_Read, MVC.BeheerTeksten.Name, new { setID = Model.SetID }).Data("onReadAdditionalData"))
        .Update(update => update.Action(MVC.BeheerTeksten.ActionNames.ResourceItems_Update, MVC.BeheerTeksten.Name).Data("onAdditionalData"))
        .Destroy(destroy => destroy.Action(MVC.BeheerTeksten.ActionNames.ResourceItems_Delete, MVC.BeheerTeksten.Name))
        )
)

除了创建新记录时,网格工作正常.它调用创建方法,将记录保存在数据库中,等等,没问题.

The grid works just fine, except when I create a new record. It calls the method to create, saves the record on the database, etc, no problem.

但是当我返回视图时,我刚刚添加的记录将作为插入表中的第一条记录的副本出现.

But when I return to the view, the record I just add appears as a duplicate of the first record inserted in the table.

是的,我知道这听起来很奇怪,但这是事实.我已经尝试过几次使用不同的值,但是我总是得到相同的结果.

Yes, I know it sounds strange but it's true. I've tried several times with different values, but I always get the same result.

所有新记录都显示为添加到网格中的第一条记录的重复.当然,如果我刷新页面,则数据正确.

Every new record is shown as a duplicate of the first record added to the grid. Off course, if I refresh the page, the data is correct.

这是一个例子. 添加新记录之前的网格.

Here's an example. The grid before adding a new record.

插入新记录后的网格.

最后,保存更改后,我得到了.如果刷新页面,则数据正确.

Finally, after saving changes, I get this. If I refresh the page, the data is correct.

这是我的创建方法.

[AcceptVerbs(HttpVerbs.Post)]
        [Domain.BasisArchitectuur.Framework.MVC.ActionFilters.MenuItem("Teksten")]
        [IsAgromilieuActieAllowed(ActieClaims.TekstenBeheren)]
        public virtual ActionResult ResourceItems_Create([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<TekstenViewModel.Tekst> resourceItems, long setID, string toepassingsCode)
        {
            List<ResourceItemDto> entities = new List<ResourceItemDto>();

            if (ModelState.IsValid && SecurityHelper.IsActieAllowed(ActieClaims.TekstenBeheren))
            {
                try
                {
                    using (IProxy<IResourceService> proxy = _proxyFactory.Create<IResourceService>())
                    {
                        foreach (TekstenViewModel.Tekst tekstenViewModel in resourceItems)
                        {
                            ResourceItemDto resourceItem = new ResourceItemDto
                            {
                                ResourceItem_ID   = tekstenViewModel.ID,
                                ResourceSet_ID    = setID,
                                Naam              = HttpUtility.HtmlDecode(tekstenViewModel.Naam),
                                Opmerking         = HttpUtility.HtmlDecode(tekstenViewModel.Opmerking),
                                Waarde            = HttpUtility.HtmlDecode(tekstenViewModel.Waarde),
                                Type_Code         = tekstenViewModel.Type,
                                Taal_Code         = tekstenViewModel.Taal,
                                ResourceWaarde_ID = tekstenViewModel.WAARDE_ID
                            };

                            entities.Add(resourceItem);
                        }

                        proxy.Client.CheckIfNameExists(entities, toepassingsCode);
                        proxy.Client.AddOrUpdateResourceItem(entities.AsEnumerable());
                    }
                }                

                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                }
            }
            else
            {
                var errMsg = ModelState.Values
                    .Where(x => x.Errors.Count >= 1)
                    .Aggregate("Model State Errors: ", (current, err) => current + err.Errors.Select(x => x.ErrorMessage));

                ModelState.AddModelError(string.Empty, errMsg);
            }

            resourceItems = GetResourceItemsList(new TekstenViewModel.ZoekCriteria { Taal = resourceItems.FirstOrDefault().Taal, ResourceSet_ID = resourceItems.FirstOrDefault().RESOURCE_SET_ID });

            return Json(resourceItems.ToDataSourceResult(request, ModelState));
        }

推荐答案

问题应该是您没有从create操作中返回带有product.ID的Json

The problem should be that you are not returning a Json with product.ID back from your create action

Create(create => create.Action(MVC.BeheerTeksten.ActionNames.ResourceItems_Create, MVC.BeheerTeksten.Name).Data("onCreateAdditionalData"))

需要返回,添加的商品带有model.Id(product => product.ID);

Need to Return , the added item with the model.Id(product => product.ID);

Kendo网格在由ID创建时跟踪物料,因此您需要将其提供回数据源

Kendo grid tracks the Items when created by the ID so you need to provide it back to the DataSource

这篇关于我的剑道网格正在复制记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆