我需要在MVC控制器中調用此方法並將UpdateRequest對象作爲json格式傳遞。我怎麼能做到這一點?如何在MVC中調用WebAPI方法並將json對象發送給它
[HttpPost]
[Route("updatecertificate")]
public void updatecertificate([FromBody] UpdateRequest certificatereviewed)
{
loansRepository.updatecertificate(certificatereviewed.Id, certificatereviewed.CertificateReview);
}
,這是輸入類:
public class UpdateRequest {
public int Id { get; set; }
public bool CertificateReview { get; set;}
}
這是我如何打電話和發獨立的變量,但現在我喜歡發類對象JSON格式。
private async Task UpdateFundingCertificateReviewed(int id, bool fundingCertificateReviewed)
{
await httpClient.PostAsync(string.Format("{0}/{1}", LoanApiBaseUrlValue, updatecertificate),null);
}