我正在尝试使用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 });
}
...
}
请求到达服务器端,但upload参数始终为null。我想我在客户端缺少一些id,但我找不到指出在哪里设置它的文档。有什么想法吗?
答案 0 :(得分:1)
我发现了我的错误。我错过了FineUpload类中的ModelBinder行(在服务器端):
using System.IO;
using System.Web.Mvc;
namespace Vizion.Web.UI.Helpers
{
[ModelBinder(typeof(ModelBinder))]
public class FineUpload
{
...
现在它完美无缺。感谢Ray Nicholus!