简体   繁体   English

如何访问在ASP.NET Core中从jquery文件上传发送的其他表单数据?

[英]How to access additional form data sent from jquery file upload in asp.net core?

I am using jquery file upload to upload large files in chunks to server. 我正在使用jquery文件上传将大文件分块上传到服务器。 I need to send additional data to server along with the file. 我需要将其他数据与文件一起发送到服务器。

I found this article that suggests adding formData as below. 我发现这篇文章建议添加如下的formData。

$form = $('#fileupload').fileupload({
            maxChunkSize: 3000000,
            url: '/FileAPI/Upload',
            formData: { example: 'test' }
         });

How can I access the formData from HttpContext.Request in asp.net core ? 如何从asp.net核心中的HttpContext.Request访问formData? Where is it available? 在哪里可以买到? Thanks for any suggestions. 感谢您的任何建议。

[HttpPost]
[Route("Upload")]

public ActionResult Upload()
{
    var CurrentContext = HttpContext.Request;
}

just add it to the function signature 只需将其添加到功能签名中

this should work 这应该工作

[HttpPost]
[Route("Upload")]
public ActionResult Upload(IEnumerable<IFormFile> files, string example)
{   
   //do something with data
}

How can I access the formData from HttpContext.Request in asp.net core ? 如何从asp.net核心中的HttpContext.Request访问formData?

From the article you provide , "formData object, formData: {example: 'test'} will arrive on server-side as POST parameter" 从您提供的文章中,“ formData对象,formData:{示例:'test'}将作为POST参数到达服务器端”

You could also try the following method to get it : 您也可以尝试以下方法来获取它:

 [HttpPost]
 [Route("Upload")]
 public void Upload()
 {
        var dict = Request.Form.ToDictionary(x => x.Key, x => x.Value.ToString());
       //In that case, you could iterate over your dictionary or you can access values directly:
        var CurrentContext = dict["example"];
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM