title: i want to disable my custom validation in edit action in asp.net mvc
body: <p><b>Model</b></p>
  
  <pre><code>public partial class MemberModel 
      {
  
          [Key]
          public int MemberID { get; set; }
  
          [Required]
          [Unique_Member]
          [StringLength(255)]
          [Display(Name = "First Name")]
          public string FirstName { get; set; }
  
  
          [Required]
          [Unique_Member]
          [StringLength(255)]
          [Display(Name = "Last Name")]
          public string LastName { get; set; }
  
          [Display(Name="Name")]
          public string FullName { get { return string.Format(FirstName + " " + LastName); } }
  
          [Required]
          [StringLength(355)]
          public string Address { get; set; }
          [Required(ErrorMessage="The City field is Required")]
          public int CityID { get; set; }
  
          [Required(ErrorMessage = "The Country field is Required")]
          public int CountryID { get; set; }
  
  
          [Required]
          [RegularExpression(@"^((0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{4}$|^\d{4}-\d{7}$", ErrorMessage = "Invalid Phone number")]
          [Unique_Member]
          public string Pin { get; set; }
  
  
          [Display(Name="Mobile No.")]
          [Required(ErrorMessage="Mobile No. Required")]
          [RegularExpression(@"^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$",ErrorMessage="Invalid Phone number")]
          public string Phone { get; set; }
  
  
          [Required]
          [EmailAddress]
          public string Email { get; set; }
  
  
          public virtual List&lt;Order_SummeryModel&gt; Order_Summeries { get; set; }
          public virtual CountryModel Country { get; set; }
          public virtual CityModel City { get; set; }
      }
  </code></pre>
  
  
  
  <p><b>Custom Validation [Unique_Member]</b></p>
  
  <p>its a custom validation for three properties "Pin","FirstName" and "LastName" which i made for create new member. It checks whether fullname and pin of new member is unique or not. </p>
  
  <p>its works perfectly for create action but in edit action this restrict me to update the member model, i want to disable it for edit action, or there is another way to update the model with disable it.</p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>  public class Unique_MemberAttribute : ValidationAttribute
      {
          private static int count;
  
          protected override ValidationResult IsValid(object value, ValidationContext validationContext)
          {
              Context_getway db = new Context_getway();
              string membervalue = value.ToString();
              //var count = db.Members.Where((x =&gt; x.Name == membervalue || x.Pin == membervalue || x.Email == membervalue)).Count();
              var count_fname = db.Members.Where(x =&gt; x.FirstName == membervalue).Count();
              var count_lname = db.Members.Where(x =&gt; x.LastName == membervalue).Count();
              var count_pin = db.Members.Where(x =&gt; x.Pin == membervalue).Count();
  
              if ((count_fname != 0)||(count_lname != 0))
              {
                  count++;
                  if (count == 2)
                  {
                      return new ValidationResult("Member Already Exist with the same Full Name (Change First Name OR Last Name)!");
  
                  }
              }
              if (count_pin != 0)
              {
                  return new ValidationResult("Member Already Exist with the same Pin!");
              }
  
  
                  return ValidationResult.Success;
  
          }
      }
      [MetadataType(typeof(MemberModel))]
      public partial class MemberModel
      {
  
      }
  </code></pre>
  
  <p><b>Member Controller (edit action)</b></p>
  
  <pre><code> [HttpGet]
          public ActionResult Edit(int? id)
          {
              if (id == null)
              {
                  return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
              }
              else
              {
                  var member = db.Members.Find(id);
                  ViewBag.CountryID = new SelectList(db.CountryModels.ToList(), "CountryID", "Country",member.CountryID);
                  ViewBag.CityID = new SelectList(db.CityModels.ToList(), "CityID", "City",member.CityID); 
                  if (member != null)
                  {
                      return View(member);
                  }
                  else
                      return HttpNotFound();
              }
          }
          [HttpPost]
          [ValidateAntiForgeryToken]
          public ActionResult Edit(MemberModel member)
          {
  
              try
              {  
                  if (ModelState.IsValid)
                  {
                      db.Entry(member).State = System.Data.Entity.EntityState.Modified;
                      db.SaveChanges();
                      TempData["Msg"] = "Update Successfully";
                      return RedirectToAction("Index");
                  }
                  else
                  {
                      ViewBag.CountryID = new SelectList(db.CountryModels.ToList(), "CountryID", "Country",member.CountryID);
                      ViewBag.CityID = new SelectList(db.CityModels.ToList(), "CityID", "City",,member.CityID); 
                      return View(member);
                  }
              }
              catch(Exception e)
              {
                  TempData["Msg"] = "Update Unsuccessfully: "+ e.Message;
                  return View();
              }
          }
  </code></pre>