简体   繁体   English

反序列化之前是否可以验证Asp.Net OData Web Api?

[英]Is possible Asp.Net OData Web Api validation before deserialization?

When I try to post string value to int property I would like to get an error 当我尝试将string值发布到int属性时,我想得到一个错误

input.propertyName : propertyName value should be of type 'Edm.Int32'

but Asp.Net OData is giving an exception message 但是Asp.Net OData提供了异常消息

input : Cannot convert the literal '3a' to the expected type 'Edm.Int32'.

This should be a validation error, not an exception IMO. 这应该是一个验证错误,而不是IMO例外。

Is there a way configuring OData to validate before type conversion? 有没有一种方法可以配置OData在类型转换之前进行验证? Or handling this kind of exceptions with field paths and validation types? 还是使用字段路径和验证类型来处理这种异常?

I am trying to achieve mapping this kind of errors with fields on my presentation and giving more suitable messages. 我试图实现将此类错误与演示文稿中的字段进行映射,并提供更合适的消息。

您可以在Odata的ASP.NET Web API中使用模型验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM