从 jQuery 文件上传插件的控制器操作返回什么?
我正在使用 Blueimp 的 jQuery 文件上传 5.6 版提供的演示页面。我可以让演示在我的 ASP.NET MVC 项目中运行,直到可以从页面上传文件。
但是,即使文件成功上传,UI 也会报告错误。我 100% 确定此错误是因为我没有从控制器操作中返回正确的信息。
这是我现有的操作:
[HttpPost]
public virtual JsonResult ImageUpload(FormCollection formdata)
{
var imagePath = Setting.Load(SettingKey.BlogImagesBasePath).Value;
for(var i = 0; i < Request.Files.Count; i++)
{
var saveFileName = string.Format("{0}\\{1}", imagePath, Request.Files[i].FileName);
Log.DebugFormat("Attempting to save file: {0}", saveFileName);
Request.Files[i].SaveAs(saveFileName);
}
return Json(new {});
}
我不知道结果的内容应该是什么。我尝试对 php 示例进行排序,但由于完全不熟悉 php,我所能做的最好的事情就是可能涉及文件名、大小和类型。
有人有工作 MVC 示例的链接或提供我将正确数据返回到插件所需的信息吗?
I'm using the demo page provided with the jQuery File Upload version 5.6 from Blueimp. I can get the demo working in my ASP.NET MVC project to the point where a file can be uploaded from the page.
However, even though the file successfully gets uploaded, the UI reports an error. I'm 100% certain this error is because I'm not returning the proper information from my controller action.
Here is my existing action:
[HttpPost]
public virtual JsonResult ImageUpload(FormCollection formdata)
{
var imagePath = Setting.Load(SettingKey.BlogImagesBasePath).Value;
for(var i = 0; i < Request.Files.Count; i++)
{
var saveFileName = string.Format("{0}\\{1}", imagePath, Request.Files[i].FileName);
Log.DebugFormat("Attempting to save file: {0}", saveFileName);
Request.Files[i].SaveAs(saveFileName);
}
return Json(new {});
}
I don't know what the content of the result should be. I tried sorting through the php example but, not being at all familiar with php, the best I could make of it is that the filename, size, and type might be involved.
Does somebody have a link to a working MVC sample or provide the information I need to return the correct data to the plugin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
帆船柔道
我认为这个问题100%满足您的需求:
jQuery 文件上传插件要求我下载文件,出了什么问题?
这里基本上是它演示的内容:
类:
操作:
所以,基本上,您只需要返回ViewDataUploadFilesResult 集合的 jsonresult。
希望有帮助。
Sailing Judo
I think this question addresses your needs 100%:
jQuery File Upload plugin asks me to download the file, what is wrong?
here's basically what it demos:
the class:
the action:
so, basically, you'd just need to return the jsonresult of the ViewDataUploadFilesResult collection.
Hope it helps.