我需要在restful web api中傳遞類的列表對象。但是我在web api中收到了null
的值。 以下是我在Web API中的代碼。如何在安靜的web api中傳遞List對象的類
Public class RequestDto
{
private string _clientId;
public string ClientId
{
get { return _clientId; }
set { _clientId= value; }
}
private List<DeliveryDocument> _deliveryDocumentInfo;
public List<DeliveryDocument> DeliveryDocumentInfo
{
get { return _deliveryDocumentInfo; }
set { _deliveryDocumentInfo = value; }
}
}
public class DeliveryDocument
{
public string DocumentName { get; set; }
public string DocumentURL { get; set; }
}
public HttpResponseMessage PostSaveManifest([FromBody] RequestDto manifestRequest)
{
//here i am receiving null value in list parameter
}
下面的調用web api的代碼。
var values = new JObject();
values.Add("ClientId", "23824");
var DeliveryDocumentInfo = new List<DeliveryDocument>();
DeliveryDocumentInfo.Add(new DeliveryDocument { DocumentName = "Document Name", DocumentURL = "D:/Documnet/test.png" });
var serOut = JsonConvert.SerializeObject(DeliveryDocumentInfo);
values.Add("DeliveryDocumentInfo", serOut);
HttpContent content = new StringContent(values.ToString(), Encoding.UTF8, "application/json");
var responsesss = client.PostAsync(Constants.URLValue + "/api/Manifest", content).Result;
您是否嘗試創建RequestDto而不是像您那樣的jobject? –
不,我不是在做..但我會嘗試.. –
@OrenHaliva它與RequestDto對象一起工作。謝謝 –