Grid errors on load when using [Required] in model

1 Answer 50 Views
Grid
Tyler
Top achievements
Rank 1
Iron
Tyler asked on 28 Apr 2021, 04:08 PM | edited on 28 Apr 2021, 04:13 PM

Hello i have a Kendo core grid that has inline edit mode turned on with create update and destroy. 

What i am trying to do is get the required validator to fire when you create/update and to my understanding you're supposed to use the [Required] attribute on the model that's populating the grid.

The problem is when i do that, my grid doesn't load, instead it immediately get an error saying X field is required and then my grid is left showing nothing in the datasource. 

Note: The controller returns sucessfully

What is the issue?

Grid implementation:

    @(Html.Kendo().Grid<AccessControlsModel>()
        .Name("kgAdmin")
        .Columns(columns =>
        {
            columns.Bound(col => col.PermissionID).Width(50).Hidden(true);
            columns.Bound(col => col.UserID).Width(100);
            columns.Bound(col => col.Initials).Width(50);
            columns.Bound(col => col.Country).Width(50).ClientTemplate("#=Country#");
            columns.Bound(col => col.Admin).Width(50).ClientTemplate("<input type='checkbox' #= Admin ? checked='checked':'' # class='chkbx admin'/>").Editable(@<text> function(e){ return false; }  </text>);
            columns.Bound(col => col.PendingStatus).Width(50).ClientTemplate("<input type='checkbox' #= PendingStatus ? checked='checked':'' # class='chkbx pendingstatus' />").Editable(@<text> function(e){ return false; }  </text>);
            columns.Bound(col => col.BOM).Width(50).ClientTemplate("<input type='checkbox' #= BOM ? checked='checked':'' # class='chkbx bom' />").Editable(@<text> function(e){ return false; }  </text>);
            columns.Bound(col => col.ProcessSheet).Width(50).ClientTemplate("<input type='checkbox' #= ProcessSheet ? checked='checked':'' # class='chkbx processsheet' />").Editable(@<text> function(e){ return false; }  </text>);
            columns.Bound(col => col.Matrix).Width(50).ClientTemplate("<input type='checkbox' #= Matrix ? checked='checked':'' # class='chkbx matrix' />").Editable(@<text> function(e){ return false; }  </text>);
            columns.Bound(col => col.Quality).Width(50).ClientTemplate("<input type='checkbox' #= Quality ? checked='checked':'' # class='chkbx quality' />").Editable(@<text> function(e){ return false; }  </text>);
            columns.Bound(col => col.Process).Width(50).ClientTemplate("<input type='checkbox' #= Process ? checked='checked':'' # class='chkbx process' />").Editable(@<text> function(e){ return false; }  </text>);
            columns.Bound(col => col.Release).Width(50).ClientTemplate("<input type='checkbox' #= Release ? checked='checked':'' # class='chkbx release' />").Editable(@<text> function(e){ return false; }  </text>);
            columns.Bound(col => col.Hold).Width(50).ClientTemplate("<input type='checkbox' #= Hold ? checked='checked':'' # class='chkbx hold' />").Editable(@<text> function(e){ return false; }  </text>);
            columns.Bound(col => col.AddItem).Width(50).ClientTemplate("<input type='checkbox' #= AddItem ? checked='checked':'' # class='chkbx additem' />").Editable(@<text> function(e){ return false; }  </text>);
            columns.Bound(col => col.Reports).Width(50).ClientTemplate("<input type='checkbox' #= Reports ? checked='checked':'' # class='chkbx reports' />").Editable(@<text> function(e){ return false; }  </text>);
            columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
        })
        .NoRecords(c => c.Template("<strong>  No data </strong>"))
        .Sortable()
        .Editable(editable =>
        {
            editable.Mode(GridEditMode.InLine);
        })
        .ToolBar(tools =>
        {
            tools.Search().Text("Search all fields...");
            tools.Excel().HtmlAttributes(new { id = "save", @class = "k-button margin-left" });
            tools.Create();
        })
        .Scrollable(c => c.Enabled(true))
        .Resizable(resize => resize.Columns(true))
        .Reorderable(r => r.Columns(true))
        .Height(750)
        .HtmlAttributes(new { style = "width:100%;" })
        .DataSource(dataSource => dataSource
            .WebApi()
            .ServerOperation(false) 
            .Model(model =>
            {
                model.Id(p => p.PermissionID);
                model.Field(p => p.UserID).DefaultValue("JEINC\\");
                model.Field(f => f.Initials);
                model.Field(f => f.Country);         
            })
            .Events(events => {
                events.RequestEnd("GridRequestEnd");
                events.Error("error_handler");
            })
            .Read(read => read.Action("GetGridData", "Admin"))
            .Create(create => create.Action("Create", "Admin"))
            .Update(update => update.Action("Update", "Admin"))
            .Destroy(destroy => destroy.Action("Delete", "Admin", new { Id = "{0}" }))
        )
     )

 

The model:

    public class AccessControlsModel
    {
        public int PermissionID { get; set; }
        [Required]
        public string UserID { get; set; }
        public string Initials { get; set; }
        [UIHint("CountriesDDL")]
        public string Country { get; set; }
        public bool Admin { get; set; }
        public bool PendingStatus { get; set; }
        public bool BOM { get; set; }
        public bool ProcessSheet { get; set; }
        public bool Matrix { get; set; }
        public bool Quality { get; set; }
        public bool Process { get; set; }
        public bool Release { get; set; }
        public bool Hold { get; set; }
        public bool AddItem { get; set; }
        public bool Reports { get; set; }
    }

 

The error (immediately on load of the grid)

 

Thanks in advance!

Tyler

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 03 May 2021, 07:52 AM

Hello Tyler,

 

Thank you for writing to us.

This is not expected and might have something to do with any custom scripts on the page. I noticed that you have these events:

            .Events(events => {
                events.RequestEnd("GridRequestEnd");
                events.Error("error_handler");
            })
Feel free to check their functions, as well as any other script on the page that seems related and let me know about the result.

 

Regards,
Eyup
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Tags
Grid
Asked by
Tyler
Top achievements
Rank 1
Iron
Answers by
Eyup
Telerik team
Share this question
or