简体   繁体   English

我如何在模型中具有必需的和非序列化的属性

[英]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. 我尝试使用[必需]和[nonSerialized]标注,但未成功。 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. 这将对NonObtrusive-Validation有所帮助,我希望这些字段完整,但我不想序列化它们。

I found a solution to my answer. 我找到了答案的解决方案。

I can use the annotation [notMapped] which is compatible with [required], [compare] ... 我可以使用与[必需],[比较]兼容的注释[notMapped] ...

I also use this :context.Configuration.ValidateOnSaveEnabled = false; 我也用这个:context.Configuration.ValidateOnSaveEnabled = false; where I filled my base because i got a problem with validation here. 我在这里填补了我的基地,因为我在这里遇到了验证问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使模型中的值与下拉列表中选择的值匹配? - How can I have the values from my model match the selected values in my dropdown lists? 如何在Composite Model上应用Required属性? - How to apply Required attribute on Composite Model? 如何使用FluentValidation验证复杂模型并且仍然可以访问模型? - How can I validate complex model using FluentValidation and still have access to model? 如何在视图中将数组模型属性显示为列表? - How can I display an array model property as a list in my view? 如何在模型中的行集列表中添加行? - How can I add rows to a collection list in my Model? 如何在可以隐藏在mvc中的属性上使用必填属性 - how to use required attribute on properties that can be hidden in mvc 是否可以覆盖模型中属性的必需属性? - Is it possible to override the required attribute on a property in a model? 是否有可以与 ASP.NET MVC 3 一起使用的属性来防止 model 字段自动包含在我的视图中? - Is there an attribute that I can use with ASP.NET MVC 3 to prevent model fields from being automatically included in my views? 如何从视图中获得双倍到我的 Model? - How can I get a double from the View into My Model? 如何在客户端将自定义ValidationAttribute呈现为“da​​ta-val-xx”属性? - How can I have a custom ValidationAttribute rendered as a 'data-val-xx' attribute on the client-side?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM