如何将IEnumurable请求发送到Web API?

时间:2020-08-02 15:16:36

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

我正在尝试通过WeB API接收请求,并且请求类类型为IEnumurable。我正在使用邮递员对其进行测试,但始终将其作为空值使用。下面是我的代码段: 当我从请求类中删除IEnumurable时,我可以从POSTMAN中获取值。

控制器代码:

[HttpPost]
[Route("PostTotalLossData")]
public IHttpActionResult PostTotalLossData([FromBody]TotalLossReviewedStatusRequest reviewedStatusReq)
{
    try
    {
        if (reviewedStatusReq != null)
        {
            var result = _iTLTT_BAL.UpdateTotalLossReviewedStatus(reviewedStatusReq);
            //return Ok(result);
            return Ok(reviewedStatusReq);
        }
        else
        {
            Log.Info("Invalid request received, Request : " + reviewedStatusReq);
            return Ok("Invalid request");
        }
    }
    catch (Exception ex)
    {
        Log.Error(ex.Message);
        throw ex;
    }           
}

请求类别:

namespace CTS.NextGen.API.TLTT.Models.Request
{
    [Serializable]
    public class TotalLossReviewedStatusRequest : IEnumerable<TotalLossReviewedStatus>
    {
        public List<TotalLossReviewedStatus> totalLossReviewedStatuses { get; set; }

        public IEnumerator<TotalLossReviewedStatus> GetEnumerator()
        {
            return this.totalLossReviewedStatuses.GetEnumerator();
            
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.totalLossReviewedStatuses.GetEnumerator();
            
        }
    }
}

邮递员请求正文:

{
"totalLossReviewedStatuses" : [
    {
  "n_claimNumber" : "123456678",
   "n_damageID" : "123rtyui89",
   "b_initiialReviewed" : "12/09/2020",
   "b_reviewed" :"Y",
   "heloo":"N"
    },
    {
  "n_claimNumber" : "123456678",
   "n_damageID" : "123rtyui89",
   "b_initiialReviewed" : "12/09/2020",
   "b_reviewed" :"Y"
    }
 ]
    
}

请帮助我。

1 个答案:

答案 0 :(得分:0)

您的请求正文应为ImageView类型,而不是array类型。将输入请求正文更改为

object