【发布时间】:2015-02-03 15:18:35
【问题描述】:
我需要使用 WebClient 调用 WebApi,其中必须将对象作为参数传递。我的 WebApi 方法类似于下面的代码:
示例 URI:localhost:8080/Api/DocRepoApi/PostDoc
[HttpPost]
public string PostDoc (DocRepoViewModel docRepo)
{
return string.enpty;
}
然后 DocRepoViewModel 是:
public class DocRepoViewModel
{
public string Roles { get; set; }
public string CategoryName { get; set; }
public List<AttachmentViewModel> AttachmentInfo { get; set; }
}
AttachmentViewModel 是:
public class AttachmentViewModel
{
public string AttachmentName { get; set; }
public byte[] AttachmentBytes { get; set; }
public string AttachmentType { get; set; }
}
新我需要从我的 MVC 控制器(不是 javascript ajax)调用 PostDoc 方法。我如何传递这个特定的参数,我可以在我的 WebApi 方法中进行调用并获取所有数据。我们可以通过WebClient 来做吗?或者有更好的方法。请帮忙。
【问题讨论】:
标签: c# asp.net webclient asp.net-web-api