0
如何禁用已在模型属性上设置的[Required]
属性。如何禁用Web api模型中属性的必需属性?
我使用new
关键字尝试了以下代码,但无法正常工作。
我也试过override
关键字以及没有工作。
ChildModel
使用BaseModel
的大部分属性,而不是创建新的模型文件并编写许多类似的属性我正在考虑做这样的事情。
public class BaseModel
{
[Required]
public string Address{ get; set; }
}
public class ChildModel : BaseModel
{
public new string Address{ get; set; }
}
任何简单的解决方案?
这个以前的问题应该会帮助你:[https://stackoverflow.com/questions/8903838/is-it-possible-to-override-the-required-attribute-on-a-property-in-a-模型?RQ = 1](https://stackoverflow.com/questions/8903838/is-it-possible-to-override-the-required-attribute-on-a-property-in-a-model?rq=1 ) – ZippyZippedUp
我试过,但它不工作:(基地和派生的解决方案。 这是什么?[MetadataType(typeof(Base.Metadata))]??任何评论? – Neo
你在[https:// stackoverflow的.com /问题/ 8903838/IS-IT-可能对覆盖最需要属性上-A-属性功能于一个模型?RQ = 1](https://stackoverflow.com/questions/ 8903838 /是否可以重写-a-model-property-in-a-model?rq = 1)这适用于我。 – ZippyZippedUp