Search code examples
odataasp.net-web-api2

Web API OData ignore properties added by client-side


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 ?


Solution

  • 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