Попробуйте следующее.
Контроллер:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Upload(HttpPostedFileBase fileData)
{
if (fileData != null && fileData.ContentLength > 0)
{
var appData = Server.MapPath("~/app_data");
var filename = Path.Combine(appData, Path.GetFileName(fileData.FileName));
fileData.SaveAs(filename);
}
return Json(true);
}
}
Index.cshtml
Просмотр:
<input type="file" name="fileInput1" id="fileInput1" data-upload-url="@Url.Action("upload")" data-uploadify-root="@Url.Content("~/scripts")" />
Layout.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>
<script type="text/javascript" src="@Url.Content("~/Scripts/myscript.js")"></script>
myscript.js
:
$(function () {
var fileInput = $('#fileInput1');
var uploadifyRoot = fileInput.data('uploadify-root');
var uploadUrl = fileInput.data('upload-url');
fileInput.uploadify({
'uploader': uploadifyRoot + '/uploadify.swf',
'script': uploadUrl,
'cancelImg': uploadifyRoot + '/cancel.png',
'fileExt': '*.jpg;*.gif;*.png;*.bmp;*.htm;*.html;*.txt;*.zip',
'fileDesc': '*.jpg;*.gif;*.png;*.bmp;*.htm;*.html;*.txt;*.zip',
'auto': true,
'multi': true,
'sizeLimit': 1048576,
'buttonText': 'Upload Files',
'onComplete': function (event, queueID, fileObj, response, data) {
alert(fileObj.name);
}
});
});