【问题标题】:Vue File Upload with Parameters带参数的Vue文件上传
【发布时间】:2019-07-21 18:36:53
【问题描述】:

嗨,伙计们,我创建了一个组件来上传文件及其到目前为止的工作,但除了数据之外,我还想传递一些参数,例如

HTML

<div class="col-md-4">
      <div class="container">
        <div class="large-12 medium-12 small-12 cell">
          <label>
            Files
      v-on:click="upload()">Submit</v-btn>
        </div>
      </div>
  </div>

脚本

import
          axios.post('/api/upload', this.files)
      .then(resuta);
    }, error => {
      console.error(error);
    });
  }

这里 (axios.post('/api/upload', this.files)) 我想包括 电子邮件:this.profile.email

因为我在后端的文件名中添加了这个参数

控制器

[HttpPost, DisableRequestSizeLimit]
    public ActionResult UploadFile(string email)
    {

        var files = Request.Form.Files;
        foreach (var file in files)
        {

                }
            }

        }
        return Ok();
    }

【问题讨论】:

  • 什么是this.files?此外,您的 fileChange 方法缺少其参数列表
  • this.files is data() { return { records: [], application: [], profile: [], files: new FormData()
  • profile 怎么可能是一个数组并且有一个.email 属性? profile.email 来自哪里以及何时/在哪里被赋值?分配后,该值是否会改变?

标签: vue.js asp.net-core axios


【解决方案1】:

鉴于this.filesFormData 实例,您应该能够set 任何您想要的字段。例如

upload () {
  this.files.set('email', this.profile.email)

  axios.post('/api/upload', this.files)...

我不再非常了解 .NET MVC,但这会在请求中添加 email 作为表单参数。

【讨论】:

    【解决方案2】:

    你可以这样用;

    HttpContext.Request.Form.Where(p => p.Key == "email").FirstOrDefault().Value;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-26
      • 1970-01-01
      • 2014-11-25
      • 1970-01-01
      相关资源
      最近更新 更多