Click here to Skip to main content
16,008,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,


I have a two classes which is having Required field for ListName. One is a Parent class. How can I avoid or escape the validation for Parent class. I have tried with
ModelState.Remove("ContactModel_ListName"); But its not working.

Below is my model class:

C#
public class ContactModel : BaseModel
   {
       public int UserId { get; set; }
       public int ListId { get; set; }

      
       [Required]
       [Display(Name = "List Name")]
       public string ListName { get; set; }
}


public class ContactUserModel
    {
        public ContactModel ContactModel { get; set; }
               
    }
Posted
Updated 10-Sep-14 5:32am
v2

I don't think you can do this. Alternatively you can set some default value for this property in your derived classes
 
Share this answer
 
You can create another model class with the properties as not Required by not specifying the attribute and use that model class wherever that will not be a mandatory field.
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900