使用webapi post实体提交时,一直提交递归异常的解决方法

2014年11月9日

我用的此方法解决的

 

http://stackoverflow.com/questions/19941808/exclude-a-type-from-model-validation

 

相关其它的

 

http://stackoverflow.com/questions/14079049/asp-net-web-api-validation-datacontract-and-datamember-required

http://stackoverflow.com/questions/14630794/correct-way-to-post-dates-to-web-api

http://stackoverflow.com/questions/14147299/json-net-jsonconverter-for-dbgeography

 

增加一个验证类

 

Public Class CustomBodyModelValidator
Implements IBodyModelValidator
Dim df As New DefaultBodyModelValidator

Public Function Validate(model As Object, type As Type, metadataProvider As Http.Metadata.ModelMetadataProvider, actionContext As Http.Controllers.HttpActionContext, keyPrefix As String) As Boolean Implements IBodyModelValidator.Validate
If TypeOf model Is Lily.Core.EntityBase Then
Return True
End If
Return df.Validate(model, type, metadataProvider, actionContext, keyPrefix)
End Function
End Class

 

然后在

 

Global.asax中增加

 

‘解决验证实体,造成递归异常的问题
‘zqonline
‘2014-11-08
GlobalConfiguration.Configuration.Services.Replace(GetType(IBodyModelValidator), New CustomBodyModelValidator())

 

 

声明: 本文采用 BY-NC-SA 协议进行授权. 转载请注明转自: 使用webapi post实体提交时,一直提交递归异常的解决方法
本文的评论功能被关闭了.