[英]How do I create the content of type multipart/form-data using c# as part of my response to Get request
I have to populate the content object present inside HttpResponseMessage which the content-type = multipart/form-data . 我必须填充HttpResponseMessage内部存在的内容对象,其内容类型= multipart / form-data。 I want to send a file and a string in the response content.
我想在响应内容中发送文件和字符串。
in the view the form tag should be something like:- 在视图中,表单标签应类似于:
<form id="formContent" method="post" enctype="multipart/form-data" action="controller/actionMethod">
and the file upload components should be like:- 文件上传组件应类似于:-
<input type="file" id="file1Upload" size="50" name="files" />
<input type="file" id="file2Upload" size="50" name="files" />
in the controller, the signature should be like this:- 在控制器中,签名应如下所示:
public string actionMethod(object model, IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
//write here what do you want to do with each file
}
....
}
notice IEnumerable<HttpPostedFileBase> files
is just added in the signature 注意
IEnumerable<HttpPostedFileBase> files
刚刚添加到签名中
hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.