Api控制器在反序列化时忽略DataMember

时间:2018-07-19 11:07:46

标签: c# asp.net-web-api dto

我有一个具有ItemId属性的CaptionDto类。 序列化此对象以返回到浏览器时,我希望ItemId名称更改为TranslationId,反之亦然。 我的问题是,它仅适用于序列化阶段,而不适用于反序列化阶段。

    [DataContract]
    public class CaptionDto
    {
        [DataMember]
        public System.Guid Id { get; set; }
        [DataMember(Name = "TranslationId", IsRequired =true)]
        public System.Guid ItemId { get; set; }
        [DataMember]
        public long StartTimeMilisec { get; set; }
        [DataMember]
        public long EndTimeMilisec { get; set; }
        [DataMember]
        public string FirstLine { get; set; }
        [DataMember]
        public string SecondLine { get; set; }
   }
   
   
     [HttpGet]
        public async Task<IHttpActionResult>  Get(itemId)
        {
            var captionDtos = await getByItemId(itemId)
            //Serialize works fine and ItemId does change to TranslationId
            return Ok(captionDtos);
        }
       
        [HttpGet]
        public IHttpActionResult Get(CaptionDto captionDto)
        {
          //Here captionDto doesn't contains the ItemId altough it is being sent
        }
       
       

0 个答案:

没有答案