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 can I put Validation on MVC Grid

how can I put required field Validation and compare field validation on syncfusion mvc Editable Grid 



1 Reply

ES Eswari S Syncfusion Team January 8, 2013 06:55 AM UTC

Hi Muhammad,
 
Thank you for using Syncfusion products.
 
Your requirement of adding validation to the grid editing can be achieved. Please refer to the following steps to achieve your requirement.
 
Step #1: Add the following scripts for validation
 
    <script src="<%= Url.Content("~/Scripts/MicrosoftMvcValidation.debug.js") %>" type="text/javascript"></script>  
    <script src="<%= Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js") %>" type="text/javascript"></script>  
    <script src="<%= Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>  
    <script src="<%= Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>    
 
Step #2: Set ClientValidationEnabled and UnobtrusiveJavaScriptEnabled as true in web.config.
 
<configuration
  ….  
  <appSettings>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
. . 
  </appSettings>
</configuration
 
Step #3: set validation attributes to the grid columns fields
 
 public class EditableCompanyShare
    {
         [Required(ErrorMessage = "CurrentRate is required.")]
        public Int32 CurrentRate
        {
            get;
            set;
        }
         [Compare("CurrentRate", ErrorMessage = "Predicted Rate should be equal to Current Rate")]
         public Int32 PredictedRate
         {
             get;
             set;
         }
    }
 
 
For your reference , we have prepared the sample and the same can be downloaded from the following link:
 

http://www.syncfusion.com/downloads/Support/DirectTrac/102431/Sample2047884833.zip

 
Please try this and let us know if you have any queries.
 
Regards,
Eswari S

               


Loader.
Live Chat Icon For mobile
Up arrow icon