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 :

            private string _PasswordConfirm;
            [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


  • 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.

    • Proposed as answer by Mike Feng Wednesday, November 14, 2012 12:16 PM
    • Marked as answer by Mike Feng Friday, November 23, 2012 11:31 AM
    Monday, November 12, 2012 1:21 PM