I have the following class
public partial class Contact
{
public Contact()
{
}
#region Primitive Properties
public virtual int Id { get; set; }
[Display(ResourceType = typeof(Common), Name = "Person_Name")]
[Required(ErrorMessageResourceName = "Validation_Required", ErrorMessageResourceType = typeof(Common))]
[StringLength(100, ErrorMessageResourceName = "Incorrect_Field_Length",
ErrorMessageResourceType = typeof(Common))]
public virtual string Name { get; set; }
[Display(ResourceType = typeof(Common), Name = "Telephone_Number")]
[DataType(DataType.PhoneNumber)]
[StringLength(100, ErrorMessageResourceName = "Incorrect_Field_Length",
ErrorMessageResourceType = typeof(Common))]
[Required(ErrorMessageResourceName = "Validation_Required", ErrorMessageResourceType = typeof(Common))]
public virtual string Telephone { get; set; }
[Display(ResourceType = typeof(Common), Name = "EmailAddress")]
[DataType(DataType.EmailAddress)]
[StringLength(255, ErrorMessageResourceName = "Incorrect_Field_Length",
ErrorMessageResourceType = typeof(Common))]
[Required(ErrorMessageResourceName = "Validation_Required", ErrorMessageResourceType = typeof(Common))]
public virtual string Email { get; set; }
[Display(ResourceType = typeof(Common), Name = "ContactType")]
public virtual ContactType ContactType { get; set; }
public virtual Company Company { get; set; }
#endregion
}
The ContactType looks like this
public partial class ContactType
{
#region Primitive Properties
public virtual int Id { get; set; }
[Display(ResourceType = typeof(Common), Name = "ContactType_Name")]
[StringLength(50, ErrorMessageResourceName = "Incorrect_Field_Length",
ErrorMessageResourceType = typeof(Common))]
[Required(ErrorMessageResourceName = "Validation_Required", ErrorMessageResourceType = typeof(Common))]
public virtual string Name { get; set; }
#endregion
}
The problem I have is that when I edit the Contact object, ModelState.IsValid is always false. This is due to the Name within the ContactType being Null, it has the correct id. This is because the ContactType is selected by a dropdown selection. I don't want to remove the validation from ContactType as it is needed when adding new ContactType objects. Any idea how I can get around this issue?
Please shout if I need to provide more information.
Cheers