首页 > 解决方案 > 动作绑定忽略继承的属性 (API)

问题描述

[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但在我的情况下,我不想将基类作为参数传递,而是派生类(并保留基类的属性。)

我怎样才能做到这一点?

标签: .netasp.net-mvcasp.net-mvc-4

解决方案


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


推荐阅读