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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to use validation rules and create custom validation rules grid

Thread ID:

Created:

Updated:

Platform:

Replies:

127659 Nov 30,2016 04:17 PM UTC Dec 9,2016 08:13 AM UTC ASP.NET Core 3
loading
Tags: Grid
Angel
Asked On November 30, 2016 04:17 PM UTC

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

Jayaprakash Kamaraj [Syncfusion]
Replied On 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. 
 
 
@{Html.EJ().Grid<Object>("FlatGrid") 
            .Datasource((IEnumerable<object>)ViewBag.DataSource) 
            .AllowPaging() 
            .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) 
            .ToolbarSettings(toolbar => 
               { 
                   toolbar.ShowToolbar().ToolbarItems(items => 
                    { 
                        items.AddTool(ToolBarItems.Add); 
                        items.AddTool(ToolBarItems.Edit); 
                        items.AddTool(ToolBarItems.Delete); 
                        items.AddTool(ToolBarItems.Update); 
                        items.AddTool(ToolBarItems.Cancel); 
                    }); 
               }) 
            .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(); 
              }).Render(); 
} 
 
 
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. 
 
Regards, 
 
Jayaprakash K. 


Aravind Ashokkumar
Replied On 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-columns>
                <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-columns>
            <e-filter-settings filter-type="Menu"></e-filter-settings>
            <e-page-settings page-size="14" page-count="5"></e-page-settings>
            <e-sort-settings>
                <e-sorted-columns>
                    ...
                </e-sorted-columns>
            </e-sort-settings>
        </ej-grid>

Jayaprakash Kamaraj [Syncfusion]
Replied On 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-columns> 
        <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> 
        .. 
 
   </e-columns> 
</ej-grid> 
 
 
 
 


Regards, 
 
Jayaprakash K. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;