title: BlueImp jQuery Upload using ASP.NET MVC
body: <p>I have been looking for a suitable image upload component for a website I'm working on, that will enable multiple image uploads, the ability to delete these individual uploads one by one, once uploaded and that plays nicely with .NET MVC.</p>
  <p>The nicest component that I've seen so far is <a href="https://blueimp.net/" rel="nofollow noreferrer">BlueImp's jQuery Upload</a>, and have downloaded the sample MVC project from here:</p>
  <p><a href="https://github.com/maxpavlov/jQuery-File-Upload.MVC3" rel="nofollow noreferrer">https://github.com/maxpavlov/jQuery-File-Upload.MVC3</a></p>
  <p>However, I do have 2 issues that I'm trying to get my head around.</p>
  <p><strong>Issue 1</strong><br />
  In my web application, the user can create a post, and on the same page as they enter the post details, prior to submitting this post to a messageboard, they need to be able to upload 1 or more images (using jQuery File Upload).</p>
  <p>The sample code in the BlueImp project above, handles the image uploads, in that the files are stored in the appropriate location on the server, and the UI is updated upon successful upload, to reflect those images that the user has uploaded.</p>
  <p>However, when the user goes to actually submit their post, in my Controller's ActionMethod, in addition to storing the normal post details, I also need to store the details (filenames more specifically) of any images that the user had uploaded for their post, so I can associate the post details with the relevant x uploaded images.</p>
  <p>What would be the best way to get this uploaded image information within the ActionMethod for submitting the post? I was thinking about storing information in the Session object that I could then sniff within the 'SubmitPost'ActionMethod, but I don't like relying on sessions if I can help it, with expiry issues. I also thought about having an 'UploadLog' table in the DB, which holds images uploaded by that user, that haven't yet been submitted (with the post), but unless I have some housekeeping process that runs periodically, this could get messy? I was hoping there might be a something simple in the Request collection that jQuery Upload provides, that lists the filenames of the images uploaded, or something similar?</p>
  <p><strong>Issue 2</strong><br />
  Once I have got around the above issue, I want to allow users to edit their existing posts, some of which will have uploaded photos associated with them.</p>
  <p>When they reach my Edit Post page, in addition to prefilling all the controls on the page with their post details that they originally supplied, I want to show the list of images that they uploaded for this post, along with the ability to either delete any of them, or upload additional images.</p>
  <p>I can see within the BlueImp sample MVC project that there is a jQuery template for both images waiting to be uploaded, and images that have successfully been uploaded, but I can't see any example within the sample application of how to populate this list of successfully uploaded images, in the 'edit post' scenario I've just described.</p>
  <p>The below is the template within my View, that renders successfully uploaded images, which is ideally what I'd like repopulated in this 'EditPost' scenario.</p>
  <pre><code>&lt;script id=&quot;template-download&quot; type=&quot;text/x-tmpl&quot;&gt;
  {% for (var i=0, file; file=o.files[i]; i++) { %}
      &lt;tr class=&quot;template-download fade&quot;&gt;
          {% if (file.error) { %}
              &lt;td&gt;&lt;/td&gt;
              &lt;td class=&quot;name&quot;&gt;&lt;span&gt;{%=file.name%}&lt;/span&gt;&lt;/td&gt;
              &lt;td class=&quot;size&quot;&gt;&lt;span&gt;{%=o.formatFileSize(file.size)%}&lt;/span&gt;&lt;/td&gt;
              &lt;td class=&quot;error&quot; colspan=&quot;2&quot;&gt;&lt;span class=&quot;label label-important&quot;&gt;{%=locale.fileupload.error%}&lt;/span&gt; {%=locale.fileupload.errors[file.error] || file.error%}&lt;/td&gt;
          {% } else { %}
              &lt;td class=&quot;preview&quot;&gt;{% if (file.thumbnail_url) { %}
                  &lt;a href=&quot;{%=file.url%}&quot; title=&quot;{%=file.name%}&quot; rel=&quot;gallery&quot; download=&quot;{%=file.name%}&quot;&gt;&lt;img src=&quot;{%=file.thumbnail_url%}&quot;&gt;&lt;/a&gt;
              {% } %}&lt;/td&gt;
              &lt;td class=&quot;name&quot;&gt;
                  &lt;a href=&quot;{%=file.url%}&quot; title=&quot;{%=file.name%}&quot; rel=&quot;{%=file.thumbnail_url&amp;&amp;'gallery'%}&quot; download=&quot;{%=file.name%}&quot;&gt;{%=file.name%}&lt;/a&gt;
              &lt;/td&gt;
              &lt;td class=&quot;size&quot;&gt;&lt;span&gt;{%=o.formatFileSize(file.size)%}&lt;/span&gt;&lt;/td&gt;
              &lt;td colspan=&quot;2&quot;&gt;&lt;/td&gt;
          {% } %}
          &lt;td class=&quot;delete&quot;&gt;
              &lt;button class=&quot;btn btn-danger&quot; data-type=&quot;{%=file.delete_type%}&quot; data-url=&quot;{%=file.delete_url%}&quot;&gt;
                  &lt;i class=&quot;icon-trash icon-white&quot;&gt;&lt;/i&gt;
                  &lt;span&gt;{%=locale.fileupload.destroy%}&lt;/span&gt;
              &lt;/button&gt;
              &lt;input type=&quot;checkbox&quot; name=&quot;delete&quot; value=&quot;1&quot;&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  {% } %}
  &lt;/script&gt;
  </code></pre>
  <p>Any help on either of the above 2 issues would be much appreciated.</p>
  <p><strong>UPDATE</strong><br />
  Issue 1 is now resolved using Darin's suggestion of creating a Guid, passing to the view, and back out to the upload function when that's called.</p>
  <p>Issue 2 I have managed to work out now and will post my solution shortly.</p>