简体   繁体   English

如何在我对Get请求的响应中使用c#创建multipart / form-data类型的内容

[英]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.

相关问题 多部分/表单数据内容类型请求 - multipart/form-data content type request 如何使用Content-Type:multipart / form-data通过Web API请求主体参数访问? - How request body parameter access by Web API using Content-Type: multipart/form-data? 发送multipart / form-data内容类型请求 - Send multipart/form-data content type request 如何从C#提交multipart / form-data HTTP POST请求 - How to submit a multipart/form-data HTTP POST request from C# 使用multipart / form-data(Confluence)在C#中上传附件 - Uploading an attachment in C# using multipart/form-data (Confluence) 在C#中使用RestClient作为多部分/表单数据上传文件 - Upload File using RestClient as multipart/form-data in c# 使用C#与NSUrlSession进行HTTP POST多部分表单数据 - HTTP POST multipart form-data with NSUrlSession using c# 如何在C#的Web服务中发送多部分/表单数据? - how to send multipart/form-data in web services that c#? 为 Swagger 的 multipart/form-data 中的文件指定内容类型 - Specify content-type for files in multipart/form-data for Swagger C#中的来自multipart / form-data请求的mod_security(Apache)con - mod_security (Apache) confrom multipart/form-data request in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM