【发布时间】:2013-05-06 21:07:42
【问题描述】:
我正在尝试使用 FineUploader,以便能够使用 Asp-Net MVC 4 在单个页面上向服务器提交多个文件。我正在使用示例中的代码:
HTML:
<div id="manual-fine-uploader"></div>
<button id="triggerUpload" class="red text_only has_text" style="margin-top: 10px;">
<span data-bind="text: 'Subir archivos'"></span>
</button>
JS:
$(document).ready(function() {
var manualuploader = $('#manual-fine-uploader').fineUploader({
debug: true,
request: {
element: $('#manual-fine-uploader'),
endpoint: "SaveArchivos"
},
autoUpload: false,
text: {
uploadButton: "<i class=\"icon-plus icon-white\"></i>"+i18n.t('seleccionarArchivos')
}
});
$('#triggerUpload').click(function() {
manualuploader.fineUploader('uploadStoredFiles');
});
});
控制器:
public class CondicionesComercialesController : Controller
{
...
[HttpPost]
public FineUploaderResult SaveArchivos(FineUpload upload)
{
// asp.net mvc will set extraParam1 and extraParam2 from the params object passed by Fine-Uploader
var dir = @"e:\upload\path";
var filePath = Path.Combine(dir, upload.Filename);
try
{
upload.SaveAs(filePath);
}
catch (Exception ex)
{
return new FineUploaderResult(false, error: ex.Message);
}
// the anonymous object in the result below will be convert to json and set back to the browser
return new FineUploaderResult(true, new { extraInformation = 12345 });
}
...
}
请求到达服务器端,但上传参数始终为空。我想我在客户端缺少一些 id,但我在文档中找不到任何指出设置位置的内容。有什么想法吗?
【问题讨论】:
-
您是否使用与github.com/Widen/fine-uploader-server/tree/master/… 相同的示例?
-
是的,相同的课程。不知道js代码是否正确。
-
你有没有通过ModelBinder?当请求到达服务器时,您看到了什么?
-
你成功了。我错过了 FineUpload 类中的 ModelBinder 行,这是我的错误。现在它完美地工作了。谢谢!
-
您能否再描述一下,但这一次,在“答案”中?然后接受这个答案?我希望遇到相同问题的其他人能够轻松找到此问题。谢谢!
标签: javascript asp.net-mvc-4 fine-uploader