Web API OData忽略客户端添加的属性 [英] Web API OData ignore properties added by client-side

查看:88
本文介绍了Web API OData忽略客户端添加的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用WebApi Odata v4调用放置到服务器"时出现错误.

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": ""
        }
    }
}

发生此错误是因为未在模型"Temp"中设置属性"test".它实际上是由javascript添加的,仅在客户端使用

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

如何使OData忽略模型中不可用的属性?

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

推荐答案

有一种方法可以处理您的情况.它不是忽略属性,而是通过将实体类型定义为开放类型来接受它们,以便它可以接受客户端未在模型中定义的动态属性,并在必要时将其存储以供将来查询.

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

这篇关于Web API OData忽略客户端添加的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆