0

Hey all I am using Kendo UI for ASP.NET MVC version 2022.R1.SP1 and I have populated a grid with one row:

enter image description here

The above screenshot grid works only when I comment out the FOREEACH statement in the code below I am using to populate that grid above is this:

@(Html.Kendo().Grid<Dtos.ConfigurationItemDto>()
    .Name("grbConfigSettings")
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .ColumnMenu()
    .Filterable()
    .ToolBar(t => t.Search())
    .Search(s => {
        s.Field(o => o.Value, "contains");
    })
    .Height("90%")
    .Selectable(s => s.Mode(GridSelectionMode.Single))
    .Resizable(r => r.Columns(true))
    .Sortable()
    .Pageable(p =>
    {
        p.Refresh(true);
        p.PageSizes((IEnumerable<int>)new List<int> { 50, 100, 250, 500 });
        p.PreviousNext(true);
        p.Input(true);
        p.AlwaysVisible(true);
    }
    )
    .Editable(g=>g.Mode(GridEditMode.InLine))
    .Columns(c =>
    {
        foreach (System.Data.DataColumn column in Model.Columns)
        {
            switch (column.DataType.ToString())
            {
                case "System.Int16":
                case "System.Int32":
                case "System.Int64":
                    c.Bound(column.ColumnName).EditorTemplateName("Integer");
                    break;
                case "System.Decimal":
                case "System.Double":
                case "System.Float":
                    c.Bound(column.ColumnName).EditorTemplateName("Number");
                    break;
                case "System.String":
                    c.Bound(column.ColumnName).EditorTemplateName("String");
                    break;
                default:
                    //etc etc
                    break;
            }
        }
        c.Bound(m => m.Id).Hidden();
        c.Bound(m => m.NameSpace);
        c.Bound(m => m.Key);
        c.Bound(m => m.Type);
        c.Bound(m => m.Value);
        c.Command(cmd =>
        {
            cmd.Edit();
        });
    })
    .Scrollable()
    .DataSource(
        ds => ds
        .Ajax()
        .PageSize(50)
        .Read(read => read.Action("Read", "Configuration"))
        .Update(update => update.Action("Update", "Configuration"))
        .Model(m =>
        {
            m.Id(c => c.Id);
            m.Field(c => c.Key).Editable(false);
            m.Field(c => c.Type).Editable(false);
            m.Field(c => c.NameSpace).Editable(false);
            m.Field(c => c.Value).Editable(true);
        }
        )
    )
)

Every time I try loading the page I get the error of:

Cannot perform runtime binding on a null reference

Which does not make any sense since I know there are at least 1 row of data in the grid.

I originally used the code here but seeing as it was posted in 2017 - its a little outdated. I have also seen this demo from Telerik's demo site but that seems to just be using jQuery and not ASP.NET MVC?

My goal would be to see what type that current row is (in the image above that would be a 4 which would indicate a numeric only value) and change the EditorTemplateName to reflect this. There will be different types of modes for this column so that is why I am needing to dynamically change that rows edit type for each row.

So, what am I missing or doing wrong here?

2
  • What do you mean by "There will be different types of modes for this column"? Commented Apr 6, 2022 at 17:44
  • @ShawnOrr Meaning one record could have only numbers for that column then the next record could only have values that need to be in a dropdown list, etc etc. That column wont have just a single type. Commented Apr 6, 2022 at 17:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.