Web API OData ignore properties added by client-side

时光总嘲笑我的痴心妄想 提交于 2019-12-11 16:08:31

问题


I get an error when I call Put to my server using WebApi Odata v4.

{
    "error": {
        "code": "",
        "message": "The request is invalid.",
        "innererror": {
            "message": "job : The property 'test' does not exist on type 'Model.Temp'. Make sure to only use property names that are defined by the type.\r\n",
            "type": "",
            "stacktrace": ""
        }
    }
}

this error happens because the property "test" is not set in the Model "Temp". it is actually added by javascript, and only used in client-side

How do I make so that OData will just ignore properties that are not available in the Model ?


回答1:


There is a way to deal with your scenario. It is not to ignore the properties, but to accept them by defining the entity type as an open type so that it can accept dynamic properties which are not defined in the model from the client and store them for future queries if necessary.

You can find the following tutorial for implementing an open type support: http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/use-open-types-in-odata-v4



来源:https://stackoverflow.com/questions/26301833/web-api-odata-ignore-properties-added-by-client-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!