[英]using plupload jquery in mvc3 HttpPostedFileBase is always null
Overview : 概述:
I have use plupload jquery to upload multiple files but when i pressed save button i am getting null values in HttpPostedFileBase 我已经使用plupload jquery上传了多个文件,但是当我按下保存按钮时,我在HttpPostedFileBase中获取了空值。
Code : 代码:
@{
ViewBag.Title = "ImageUpload";
}
<link href="@Url.Content("~/Scripts/plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css")"
rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Scripts/plupload/js/jquery.ui.plupload/css/jquery.ui.plupload.css")"
rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/plupload/js/plupload.full.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/plupload/js/jquery.ui.plupload.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/plupload/js/jquery.plupload.queue/jquery.plupload.queue.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#uploader").pluploadQueue({
// General settings
runtimes: 'html5,html4,gears,flash,silverlight',
url: '@Url.Action("UploadImage")',
max_file_size: '10mb',
chunk_size: '1mb',
unique_names: true,
button_browse_hover: true,
multiple_queues: true,
dragdrop: false,
// Resize images on clientside if we can
resize: { width: 320, height: 340, quality: 90 },
// Specify what files to browse for
filters: [
{ title: "Image files", extensions: "jpg,gif,png,jpeg,bmp" },
{ title: "Zip files", extensions: "zip" },
{ title: 'PDF files', extensions: 'pdf' },
{ title: "Excel Files", extensions: "xls,xslx,csv" },
],
// Silverlight settings
silverlight_xap_url: '@Url.Content("~/Scripts/plupload/plupload.silverlight.xap")'
});
// Client side form validation
$('form').submit(function (e) {
var uploader = $('#uploader').pluploadQueue();
// Files in queue upload them first
if (uploader.files.length > 0) {
if (uploader.files.length < 9) {
// When all files are uploaded submit form
uploader.bind('StateChanged', function () {
if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
$('form')[1].submit();
}
});
uploader.start();
} else {
alert('Number of files more than 8.');
}
return false;
}
else {
alert('You must queue at least one file.');
}
return false;
});
});
</script>
@using (Html.BeginForm("ImageUpload", "Image", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div id="uploader">
<p>
You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
</div>
<p>
<input type="submit" value="Save" id="uploadFile" name="uploadFile" />
</p>
}
In my controller :
public ActionResult ImageUpload()
{
return View();
}
I have this controller which is executed on submit of form . 我有这个控制器,它在form提交时执行。
[HttpPost]
public string ImageUpload(HttpPostedFileBase FileData)
{
FileData = Request.Files[0];
if (FileData.ContentLength > 0)
{
var fileName = Path.GetFileName(FileData.FileName);
var path = Path.Combine(Server.MapPath("~/Content"), fileName);
FileData.SaveAs(path);
}
return "Files was uploaded successfully!";
}
replace url: '@Url.Action("UploadImage")', with url: '@Url.Action("ImageUpload")', 用url:'@ Url.Action(“ ImageUpload”)'替换url:'@ Url.Action(“ UploadImage ”)',
this works for me 这对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.