Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Start with a controller:</p> <pre><code>public class HomeController : Controller { public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(HttpPostedFileBase file) { if (file != null &amp;&amp; file.ContentLength &gt; 0) { // If the user selected a file it will be stored // in the special App_Data folder var path = Server.MapPath("~/App_Data"); var filename = Path.Combine(path, file.FileName); file.SaveAs(filename); } return RedirectToAction("Index"); } } </code></pre> <p>then a view:</p> <pre><code>&lt;script src="&lt;%= Url.Content("~/Scripts/jquery-custom-file-input.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt; &lt;% using (Html.BeginForm("index", "home", FormMethod.Post, new { enctype = "multipart/form-data", id = "myForm" })) { %&gt; &lt;input type="button" class="upload" value="Add a file" /&gt; &lt;input type="submit" value="Upload" /&gt; &lt;% } %&gt; </code></pre> <p>and finally a javascript file to apply the plugin to the button and scriptify the markup:</p> <pre><code>$(function() { $('.upload').file().choose(function (e, input) { // The controller action expects the file input to be named "file" input.attr('name', 'file'); // let's hide the ugliness input.hide(); // append the file input to the original form // that we will be posting to the server $(input).appendTo('#myForm'); }); }); </code></pre> <p>Must read blog before ever using <code>Request.Files</code> in an ASP.NET MVC controller action: <a href="http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx" rel="nofollow">Uploading a File (Or Files) With ASP.NET MVC</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload