Taghelpers Vs Html Helper Validation for Kendo Default template projects

1 Answer 192 Views
Grid
Rajesh
Top achievements
Rank 1
Iron
Rajesh asked on 02 Aug 2023, 03:32 PM

Hello i was just curious if there is any difference between html validation vs tag helper validation.? I am using the basic template that kendo provides to create a new project and i have observed the differences that by default html helper project provides validation but tags option doesn't create validation .Am i missing anything?

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 03 Aug 2023, 08:26 AM

Hello Rajesh,

Indeed, your observations are correct, the TagHelper implementation of the ASP.NET Core components is not strongly-typed. The Grid is built depending on the options of the Grid and it does not have access to the Model. For this reason, the DataAnnotations are not available when using TagHelpers.

This is further discussed within the following forum thread:

https://www.telerik.com/forums/taghelpers-behavior-different-than-razor-syntax

If you would like to apply validation to certain columns, then you would have to do so by setting up the <validation> tag. It is part of the schema model declaration of the data source.

        <kendo-grid name="grid" height="550">
           ...
            <datasource type="DataSourceTagHelperType.Ajax" page-size="20">
                <schema data="Data" total="Total">
                    <model id="OrderID">
                        <fields>
                            <field name="OrderID" type="number" editable="false"></field>
                            <field name="ShipName" type="string"></field>
                            <field name="OrderDate" type="date">
                                <validation required="true" />
                            </field>
                            <field name="ShipCity" type="string"></field>
                            <field name="Freight" type="number"></field>
                        </fields>
                    </model>
                </schema>
                ...
            </datasource>
        </kendo-grid>

If you want to implement a custom validation rule like the field should start with a capital letter or change the messages, there is a need to extend the validator as shown in the script in this demo source:

 

Let me know in case additional clarifications are needed.

Regards, Mihaela Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Tags
Grid
Asked by
Rajesh
Top achievements
Rank 1
Iron
Answers by
Mihaela
Telerik team
Share this question
or