How to set MaxLength of input in child grid (.net core)?

1 Answer 545 Views
Grid
SK
Top achievements
Rank 2
Iron
Iron
SK asked on 17 Sep 2021, 02:39 PM

Hello, I am looking to limit the length of "Comment" to 1000 characters. Adding custom style via HtmlAttributes does not apply it to the input attributes and I am unsure how. Any insight would be great. 

                                    @(Html.Kendo().Grid<SomeUI.Areas.Models.SomeCommentsModel>()
                                     .Name("SomeCommentsGrid_#=PONum#_#=lineNum#") 
                                      .Columns(columns =>
                                      {
                                          columns.Bound(p => p.comment).Title("Comment").Width(100);
                                          columns.Bound(p => p.updatedBy).Title("Updated By").Width(15).Editable("readOnlyCol");
                                          columns.Bound(p => p.lastUpdated).Title("Last Updated").Width(25).Format("{0:MM/dd/yyyy}").Editable("readOnlyCol");
                                      })
                                      .ToolBar(toolbar => {
                                          toolbar.Create();
                                          
                                      })
                                      .Editable(editable => editable.Mode(GridEditMode.InCell))
                                      .Selectable(selectable => selectable
                                        .Mode(GridSelectionMode.Single))
                                      .Events(ev => ev.Change("onChange"))
                                      .DataSource(dataSource => dataSource
                                        .Ajax()
                                        .Read(read => read.Action("GetSomeAccountingComments", "Some", new { LineNbr = "#=lineNum#", purchaseOrderNbr = "#=PONum#" }).Data("GetFacilityCode"))
                                        .Sort(sort => sort.Add("lastUpdated").Descending())
                                        .PageSize(10)
                                        )
                                        .Sortable()
                                        .Pageable()
                                        .Width(1000)
                                        .ToClientTemplate())

1 Answer, 1 is accepted

Sort by
1
Accepted
JG
Top achievements
Rank 2
Iron
answered on 20 Sep 2021, 07:50 AM | edited on 20 Sep 2021, 07:52 AM

Have you tried setting the [StringLength] annotation on the property in your model? 

        [StringLength(1000)]
        public string Comments { get; set; }

You can find more information on kendo validation here

SK
Top achievements
Rank 2
Iron
Iron
commented on 20 Sep 2021, 02:16 PM

That worked. I had only tried MaxLength but not StringLength. Thanks.
Tags
Grid
Asked by
SK
Top achievements
Rank 2
Iron
Iron
Answers by
JG
Top achievements
Rank 2
Iron
Share this question
or