我对视图模型的属性具有自定义验证属性。我需要在IsValid方法中使用不同的逻辑,此逻辑取决于HTTP方法(Post,Put等)
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true, Inherited = false)]
public class CustomAttribute: ValidationAttribute
{
public CustomAttribute() : base() {}
protected override ValidationResult IsValid(object value, ValidationContext validationContext){}
}
//Model looks like:
public class ViewModel
{
[CustomAttribute]
public string Field{ get; set; }
}
是否可以在IsValid方法中获取HttpContext?还是可以通过属性构造函数将httpcontext / http方法发送到属性?