none
Can i have a required and nonSerialized field RRS feed

  • Question

  • I have a property in my model and i want this property to be required but non serialized

    It's a ConfirmPassword field, I don't want to serialized this information but I would like to use unobtrusive-validation with [required] annotation

    is it possible to do what I want ?

    i already tried this :

            [NonSerialized]
            private string _PasswordConfirm;
    
    
            [DataType(DataType.Password)]
            [Required]
            [Compare("PasswordHash", ErrorMessage = "Passwords do not match.")]
            public string PasswordConfirm { get { return this._PasswordConfirm; } set { this._PasswordConfirm = value ;} }

    But I need to complete PasswordConfirm or I get an error : "

    DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details."

    Sunday, November 11, 2012 8:40 PM

Answers

  • How will the server side validate that the property has a value if it is not serialized?

    BTW, if Password is required, PasswordConfirm will also be required by association. IMHO, it's better to leave it off, since "PasswordConfirm is required" is a less helpful error message than "Passwords do not match"


    This signature unintentionally left blank.

    Monday, November 12, 2012 1:21 PM