Note that there are some explanatory texts on larger screens.

plurals
  1. POComplex Data Validation using Data Annotations
    primarykey
    data
    text
    <p>I have the following class</p> <pre><code>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 } </code></pre> <p>The ContactType looks like this</p> <pre><code>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 } </code></pre> <p>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?</p> <p>Please shout if I need to provide more information.</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload