我的 PriceDM 类中有这个属性。
[MaxLength(8)]
public decimal Price { get; set; }
public void AddPrice([FromBody]PriceDM vm)
{
}
我一直收到这个错误
{"Message":"发生错误。","ExceptionMessage":"无法将 'System.Decimal' 类型的对象转换为 'System.Array' 类型。","ExceptionType":"System.InvalidCastException"," StackTrace":" 在 System.ComponentModel.DataAnnotations.MaxLengthAttribute.IsValid(Object value)\r\n 在 System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(Object value, ValidationContext validationContext)\r\n 在 System.ComponentModel.DataAnnotations。 ValidationAttribute.GetValidationResult(Object value, ValidationContext validationContext)\r\n at System.Web.Http.Validation.Validators.DataAnnotationsModelValidator.Validate(ModelMetadata metadata, Object container)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator。ShallowValidate(ModelMetadata 元数据、ValidationContext 验证上下文、对象容器)\r\n
在 System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata 元数据,ValidationContext 验证上下文,对象容器)\r\n
在 System.Web.Http.Validation.DefaultBodyModelValidator.ValidateProperties(ModelMetadata 元数据,ValidationContext 验证上下文)\r\n System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container)\r\n
at System.Web.Http.Validation.DefaultBodyModelValidator.Validate(Object model, Type type, ModelMetadataProvider metadataProvider, HttpActionContext actionContext, String keyPrefix)\r\n 在 System.Web.Http.ModelBinding.FormatterParameterBinding.<>c_ DisplayClass1.b_0(对象模型)\r\n 在 System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass361.<>c__DisplayClass38.<Then>b__35()\r\n at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass49.<ToAsyncVoidTask>b__48()\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func
1 func, CancellationToken cancelToken)"}
我可以不使用带小数的 MaxLength 吗?