简体   繁体   中英

How can I have a required and nonSerialized attribute in my model

In my Model I have things like that :

    [...]

    public string PasswordConfirm { get; set; }

    public string Captcha { get; set; }

    [...]

I would like that these two attributes are required but not serializable

I tried tu use [required] and [nonSerialized] annontations but without success. I already saw this post

But I don't know how to do what I want. It will be helpful for NonObtrusive-Validation, i want these field complete but i don't want to serialized them.

I found a solution to my answer.

I can use the annotation [notMapped] which is compatible with [required], [compare] ...

I also use this :context.Configuration.ValidateOnSaveEnabled = false; where I filled my base because i got a problem with validation here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM