The original answer recommended using the Nuget package:
https://www.nuget.org/packages/Uploadfy/
But it is old and may not fit if the jQuery version is the latest. Then download the Zip at this address:
http://www.uploadify.com/download/
Put the files into your project as follows:
~/Scripts/jquery.uploadify.js
~/Content/UploadifyContent/uploadify.swf
~/Content/UploadifyContent/uploadify-cancel.png
~/Content/UploadifyContent/uploadify.css
Example of View
@{
ViewBag.Title = "Index";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Upload Files</title>
@Scripts.Render("~/bundles/jquery")
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.uploadify.js")"></script>
<link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/UploadifyContent/uploadify.css")" />
<script type="text/javascript">
$(function () {
$('#file_upload').uploadify({
'swf': "@Url.Content("~/Content/UploadifyContent/uploadify.swf")",
'cancelImg': "@Url.Content("~/Content/UploadifyContent/uploadify-cancel.png")",
'uploader': "@Url.Action("Upload", "Home")",
'onUploadSuccess' : function(file, data, response) {
$("#uploaded").append("<img src='" + data + "' alt='Uploaded Image' />");
}
});
});
</script>
</head>
<body>
<div>
Click Select files to upload files.
<input type="file" name="file_upload" id="file_upload" />
</div>
<div id="uploaded">
</div>
</body>
</html>
Example of Controller (Controllers Homecontroller.Cs)
public ActionResult Index()
{
return View();
}
public ActionResult Upload()
{
var file = Request.Files["Filedata"];
string savePath = Server.MapPath(@"~\Content\" + file.FileName);
file.SaveAs(savePath);
return Content(Url.Content(@"~\Content\" + file.FileName));
}
I did all this and nothing... I can’t install the package because the jQuery version used in the package is too old and accurate for the version I use in this project. ?
– Luiz Negrini
@Luiznegrini I updated the answer. See now.
– Leonel Sanches da Silva
Still nothing appears the way you said... suddenly it would be more interesting to implement in the hand... just know that nothing appears when I click the button to confirm at the end of the form.
– Luiz Negrini
great, but every photo I add it rejects. Give the 404 in the description.
– Luiz Negrini
@Luiznegrini I forgot to say that the methods are implemented in
HomeController
for this example. I will change the answer again.– Leonel Sanches da Silva
Problem solved! I just had to change the controller in the script and it was hehe! I just wanted to ask a question, it is good practice to use Request.Files or change the signature of the method to "Httpfilebase"?
– Luiz Negrini
@Luiznegrini The coolest is you use
public HttpPostedFileBase Arquivo { get; set; }
in theModel
. Then the file becomes oneproperty
much easier to be manipulated.– Leonel Sanches da Silva