【发布时间】:2018-07-09 18:04:15
【问题描述】:
我有一个 API,其中有一个同步控制器。 这个控制器只有一个动作函数:ActionRequest
public IHttpActionResult ActionRequest([FromBody]ActionRequestDto model)
{
//EXAMPLE OF PASSING AND ARTICLE IN OBJECT THREW POST METHOD
ArticleDto article = null;
if(model.ActionType == "Article"){
article = (ArticleDto)model.Object; //Problem ==> model.Object looses all articles information and cannot be cast to article
}
}
这个功能应该像路由器一样工作。它读取操作请求并调用相应的存储库。
ActionRequest 对象有这样的结构:
public class ActionRequestDto
{
public string ActionType { get; set; }
public string ObjectType { get; set; }
public bool Transmited { get; set; } = false;
public DateTime CreationDate { get; set; }
public int RequestNumber { get; set; }
public string Reference { get; set; }
public BaseDto Object { get; set; }// this is where the data is passed.
//it can be any type extending from BaseDto (ArticleDto, CustomerDto... )
}
我需要获取最终对象,而不仅仅是控制器中的基础对象,以便将其传递给服务。
如何更改反序列化行为,但仅针对此操作或至少针对此控制器?
【问题讨论】:
标签: c# .net controller json.net json-deserialization