The error you get most likely indicates that there is some problem with the server-side action that should handle the file download. I suspect some kind of exception is excluded.
Try using the following controller:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var appData = Server.MapPath("~/app_data");
var filename = Path.Combine(appData, Path.GetFileName(file.FileName));
file.SaveAs(filename);
}
return Json(true);
}
}
jquery uploadify. jquery 1.5.1 2.1.4 , , , , .
index.cshtml:
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.5.1.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/swfobject.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.uploadify.v2.1.4.js")"></script>
<input type="file" name="fileInput1" id="fileInput1" />
<span id="result"></span>
<a href="javascript:$('#fileInput1').uploadifyUpload();">Upload File</a>
<script type="text/javascript">
$(document).ready(function () {
$("#fileInput1").uploadify({
uploader: '@Url.Content("~/Scripts/uploadify.swf")',
script: '@Url.Action("Upload", "Home")',
fileDataName: 'file',
buttonText: 'File Input 1...',
multi: false,
sizeLimit: 22222222222,
simUploadLimit: 1,
cancelImg: '@Url.Content("~/Scripts/cancel.png")',
auto: false,
onError: function() {
alert('some error occurred. Sorry');
},
onComplete: function (event, queueId, fileObj, response, data) {
alert(response);
}
});
});
</script>