grid int? foreign key in line edit error

3 posts, 0 answers
  1. Adam
    Adam avatar
    2 posts
    Member since:
    Mar 2019

    Posted 29 Jul 2019 Link to this post

    I have grid with nullable int foreign key:

    Create method work as expected, foreign key value is present in the model, but when i try to edit foreign key value to null, or cancel edit without setting value, i'm getting javascript error:

    VM1494:3 Uncaught TypeError: Cannot set property 'Value' of null
        at eval (eval at setter (kendo.all.js:2118), <anonymous>:3:24)
        at o._set (kendo.all.js:4963)
        at o.accept (kendo.all.js:5180)
        at kendo.all.js:7018
        at init._eachItem (kendo.all.js:6996)
        at init._cancelModel (kendo.all.js:7014)
        at init.cancelChanges (kendo.all.js:6880)
        at init.cancelRow (kendo.all.js:61601)
        at init._editCancelClick (kendo.all.js:61319)
        at HTMLAnchorElement.proxy (VM1001 jquery-3.3.1.js:10268)


    I tried GridForeignKey template and custom template with ValuePrimitive set to true.

    Custom template:

        Html.Kendo().DropDownListFor(m => m)



    public class DictionaryTypeModel
        public DictionaryTypeModel() { }
        public int Id { get; set; }
        public string Code { get; set; }
        public string Name { get; set; }
        public int? ParentId { get; set; }
        public string Deleted { get; set; }



                .Columns(c =>
                    c.Bound(m => m.Name);
                    c.Bound(m => m.Code);
                    c.Bound(m => m.Deleted);
                    c.ForeignKey(m => m.ParentId, (List<RDEapp.Models.TypSlownikaModel>)ViewData["dictionaryType_Data"], "Id", "Name")
                    c.Command(command =>
                        command.Custom("Delete").IconClass("k-icon k-i-delete").Click("deleteType");
                .ToolBar(toolbar => toolbar.Create().Text("Add dictionary type"))
                .Editable(edit => edit.Mode(GridEditMode.InLine).DisplayDeleteConfirmation(false))
                .Selectable(selectable => selectable
                .DataSource(dataSource => dataSource
                    .Model(model =>
                        model.Id(u => u.Id);
                        model.Field(u => u.Id).Editable(false);
                        model.Field(u => u.Deleted).Editable(false).DefaultValue("N");
                        model.Field(u => u.ParentId.Value).Editable(true);
                        model.Field(u => u.Name).Editable(true);
                        model.Field(u => u.Code).Editable(true);
                    .Read(u => u.Action(RDEapp.Controllers.AdminController.NazwyMetod.DictionaryTypeRead, RDEapp.Controllers.AdminController.Name))
                    .Create(create => create.Action("AddDictionaryType", RDEapp.Controllers.AdminController.Name))
                    .Update(upd => upd.Action("EditDictionaryType", RDEapp.Controllers.AdminController.Name))
                    .Destroy(del => del.Action("DeleteDictionaryType", RDEapp.Controllers.AdminController.Name))
                    .Events(e => e.Error("crudErrors"))
  2. Tsvetomir
    Tsvetomir avatar
    757 posts

    Posted 31 Jul 2019 Link to this post

    Hi Adam,

    I have noticed that within the model, the field is not marked as nullable. Can you ensure that it is marked as nullable, and let me know on your observations.

    For your reference, I am attaching a sample project with a Kendo UI Grid. One of the columns of the grid is a foreign key column. I have set the fields to allow for null values and it appears that a null value is submitted to the remote endpoint without throwing any exceptions.

    In case the issue is still present, modify the sample project and send it back to me.

    Best regards,
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Adam
    Adam avatar
    2 posts
    Member since:
    Mar 2019

    Posted 31 Jul 2019 in reply to Tsvetomir Link to this post

    U mean thad Id field is not marked as nullable? It cannot be becouse it is Primary Key and it may cause other errors in application. I manager to get around this error by adding -1 to ParentId in Foreign Key model but now i need to check this in CRUD methods.
Back to Top