Asp.net mvc MVC控制器未捕获从Vue.JS UI上载的文件
因此,在我的Vue组件中,我有以下文件上载对话框Asp.net mvc MVC控制器未捕获从Vue.JS UI上载的文件,asp.net-mvc,vue.js,axios,form-data,formcollection,Asp.net Mvc,Vue.js,Axios,Form Data,Formcollection,因此,在我的Vue组件中,我有以下文件上载对话框 <div class="file has-name is-right"> <label class="file-label"> <input class="file-input" type="file" v-on:change="HandleFileUpload" accept=".pdf"> <span class="file-cta"> <span clas
<div class="file has-name is-right">
<label class="file-label">
<input class="file-input" type="file" v-on:change="HandleFileUpload" accept=".pdf">
<span class="file-cta">
<span class="file-icon">
<i class="icon-file-pdf"></i>
</span>
<span class="file-label">
Choose a file…
</span>
</span>
<span class="file-name" v-text="UploadFileName" style="width: 16em" />
</label>
</div>
最后是我的MVC控制器,问题出在哪里
[HttpPost]
public ActionResult Upload(FormCollection data)
{
var Foo= data.Get("Foo").Trim();
var Files = data.Get("File");
/* Rest of the method */
}
MVC控制器中的文件是空的,尽管当我使用开发人员工具检查它时,在JS和网络调用中填充了实际的文件数据。我是否在与FormCollection的FormData交互中遗漏了什么?Hm,试试这种方法,我刚刚检查了一个使用ASP.NET和axios发布的web应用程序,我的JS看起来与你的非常相似,在ASP.NET中,我基本上是这样做的:
HttpContext=System.Web.HttpContext.Current;
HttpPostedFile postedFile=context.Request.Files.Count>0
? context.Request.Files.Get(0)
:null;
这是有效的。我仍然不知道为什么我的FormCollection方法不起作用,但这提供了一个我能够做我需要的事情的案例。谢谢
[HttpPost]
public ActionResult Upload(FormCollection data)
{
var Foo= data.Get("Foo").Trim();
var Files = data.Get("File");
/* Rest of the method */
}