Wednesday, February 25, 2015

Validation Group in MVC

Hi friends,

Today I am going to demonstrate how to implement validation group in MVC.

For this you have to download one validation group jquery and and one validation group dll
Suppose we have customer model, in which we have Name and Email property. We validate this two property on two different buttons.

Step 1 : Add McjDevelopment.Mvc3ValidationGroups.dll in your project.

Step 2 : Add jquery.validate.unobtrusive.validationgroups.js in your project.

Step 3 : Create Customer Model

 public class Customer
    {
        [Required]
        [ValidationGroup("Submit1")]
        public string Name { getset; }
 
        [Required]
        [ValidationGroup("Submit2")]
        public string Email { getset; }
    }

Step 4 : Update your view to use ‘jquery.validate.unobtrusive.validationgroups.js’ immediately after ‘jquery.validate.unobtrusive.js’ (or ‘jquery.validate.unobtrusive.min.js’)








Step 5 : Update your view to include where you want each groups Validation to appear
















and don't forget to add "data-val-valgroup-name" tag at you buttons.

Results : When you click Submit1 button














When you click on Submit2 button













McjDevelopment.Mvc3ValidationGroups.Release.0.3.0.0.zip


Monday, February 9, 2015

How to ignore a certificate error - without the certificate



Hi Friends,

If you getting error like "Could not establish trust relationship for the SSL/TLS secure channel".

Do following two things

1) Add using System.Net; at your class

2) Add below line before calling your service method
 
ServicePointManager.ServerCertificateValidationCallback += 
(sender, cert, chain, sslPolicyErrors) => true;
 
 
The above line returning true will allow ignoring the validation error.