【发布时间】:2017-07-13 08:23:53
【问题描述】:
我想编写一个自定义属性,我可以用它来装饰 ViewModel 属性,这样,当发布 ViewModel 时,我可以检查哪些发布的属性具有此属性并运行一些逻辑。 我正在尝试设置条件,这不会以任何方式影响验证。
[SetsCondition(SomeEnumerationValue)]
public Fund SelectedFund {get;set;}
...
other properties
然后在控制器中。
[HttpPost]
public IActionResult SelectFund(SelectFundViewModel model){
if(ModelState.IsValid){
//check which properties have the SetsCondition Attribute
//read the SomeEnumerationValue for them
..
//profit
}
}
只是不太确定我应该从哪种属性继承,或者就此而言,如何检查特定的 ViewModel 属性是否被某个属性修饰。
非常感谢任何帮助
【问题讨论】:
标签: c# asp.net-core-mvc custom-attributes