We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to use validation rules and create custom validation rules grid

Hello forum
I cant seem to find how to use validation rules and custom validation rules on aspnet core on a grid,
if anyone could help me out with this I would highly appreciate it

3 Replies

JK Jayaprakash Kamaraj Syncfusion Team December 1, 2016 03:17 PM UTC

Hi Angel, 
Thank you for contacting Syncfusion support. 
We can set validation rules to Grid Columns using below code example. Please refer to the below help document and code example. 
            .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) 
            .ToolbarSettings(toolbar => 
                   toolbar.ShowToolbar().ToolbarItems(items => 
            .Columns(col => 
                  col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).ValidationRules(v => v.AddRule("required", true).AddRule("number", true)).Add(); 
                  col.Field("CustomerID").HeaderText("Customer ID").ValidationRules(v => v.AddRule("required", true).AddRule("minlength", 3)).Add(); 
                  col.Field("ShipCity").HeaderText("Ship City").Add(); 
                  col.Field("Freight").HeaderText("Freight").EditType(EditingType.Numeric).ValidationRules(v => v.AddRule("range", "[0,1000]")).Add(); 
                  col.Field("ShipCountry").HeaderText("Ship Country").Add(); 
We need to refer  jquery.validate.min.js and jquery.validate.unobtrusive.min.js scripts for validation. So, please refer to these script files in your sample. 
Jayaprakash K. 

AA Aravind Ashokkumar December 8, 2016 04:53 AM UTC

Hi Team,

Since Net core does not widely support Razor syntax, could you please help us provide more examples with Tag Helper Syntax.
I would nee your help for adding validation rules using Tag Helper syntax.

For example, for ej-grid the tag helper syntax is

<ej-grid id="grid_sample" allow-paging="true" allow-resize-to-fit="true" allow-resizing="true" allow-sorting="true" allow-multi-sorting="true" allow-scrolling="true" allow-searching="true" >
                <e-column field="ToolTip" header-text="ToolTip"></e-column>
                <e-column field="Remark" header-text="Remark"></e-column>
                <e-column field="RecordStatus" header-text="Record Status"></e-column>
            <e-filter-settings filter-type="Menu"></e-filter-settings>
            <e-page-settings page-size="14" page-count="5"></e-page-settings>

JK Jayaprakash Kamaraj Syncfusion Team December 9, 2016 08:13 AM UTC

Hi Angel, 
We have created a ASP.NET core sample with validations using tag helpers. Please refer to the below code example and sample. 
<ej-grid id="FlatGrid" allow-paging="true"> 
    <e-datamanager url="//mvc.syncfusion.com/Services/Northwnd.svc/Orders/?$top=45" offline="true"></e-datamanager> 
    <e-edit-settings allow-adding="true" allow-deleting="true" allow-editing="true" edit-mode="Normal" /> 
    <e-toolbar-settings show-toolbar="true" toolbar-items='new List<string>() { "add", "edit", "delete", "update", "cancel", "search" }' /> 
        <e-column field="OrderID" is-primary-key="true" header-text="Order ID" text-align="Right"  width="70"></e-column> 
        <e-column field="CustomerID" header-text="Customer ID" width="80" validation-rules='new Dictionary<string, object>() { { "required",true}, { "minlength",3} }' ></e-column> 

Jayaprakash K. 

Live Chat Icon For mobile
Up arrow icon