【发布时间】:2017-10-07 10:00:00
【问题描述】:
有人知道,如何不允许控制器中的其他属性使用注释或其他方法?
例如,我有一个模型
[required]
public string user_name {get;set;}
[required]
public string password {get;set;}
然后在请求中我发送这个正文:
{
"user_name" : "user",
"password" : "12345",
"other_property" : "here is the problem"
}
问题是验证通过了,例如我需要发送类似“属性不允许”之类的响应
【问题讨论】:
-
为什么传递其他属性是否重要?为什么你希望它验证失败?
-
我需要向用户表明此属性或其他属性在控制器中不起作用或不允许,在这种情况下是因为 api 是公共的,我需要表明它可以和不能执行api
标签: c# asp.net-web-api annotations asp.net-web-api2