【问题标题】:Action binding ignores inherited properties (API)动作绑定忽略继承的属性 (API)
【发布时间】:2021-07-01 07:35:27
【问题描述】:
[ResponseType(typeof(PlanningRestGet))]
public HttpResponseMessage Put(int id, [FromBody] PlanningRestPut model)
{
    return CallAndPrepareResponse(c => c.UpdatePlanning(id, model));
}

我创建了一个具有两个新属性的新“BaseRestPut”类,并让 PlanningRestPut 类继承了它。

但是现在当动作被执行时,来自基类的属性在模型对象中为空。

我已阅读此https://www.tutorialdocs.com/article/webapi-data-binding.html,但在我的情况下,我不想将基类作为参数传递,而是将派生类传递(并保留基类的属性。)

我怎样才能做到这一点?

【问题讨论】:

    标签: .net asp.net-mvc asp.net-mvc-4


    【解决方案1】:

    这是因为我的基类缺少 [DataContract] 装饰器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多