using slick upload with mvc 2 and jquery / ajax
After working with Patrica, this issue has been solved. We ran into a couple more snags, but the basics are as follows:
The main thing at work here is a limitation in SlickUpload's design: you can't remove a SlickUpload control from the DOM once it's been added and then readd it again later. This will be solved in SlickUpload6, but is unfortunately a limitation with the current version. To solve this, we hid the control when the tab or dialog was invisible, instead of actually removing it.
There is also a SlickUpload minor version release (5.5.9) that adds a get_UploadId() method, to make getting the upload id for the current upload easier.
This code (from above):
kw_uploadId: document.getElementById("kw_uploadId").value,
becomes:
kw_uploadId: theThing.get_UploadId(),
You can get the latest version here: SlickUpload 5.5.9
I hate iframes, but I think that is the easiest route to go here.
Alternatively, you could use jQuery form plugin http://malsup.com/jquery/form/
$('#YOURFORM').ajaxForm({target:'#YOURFORM'}); //replace form with result HTML
Well, It was actually much simpler then i expected. here's what I've got and it works:
function v2SetUpPhotoDialog() { theThing = kw.get("<%=SlickUpload1.ClientID %>"); theThing.add_OnUploadEnded(function (data) { var data = { kw_uploadId: document.getElementById("kw_uploadId").value, kw_uploadExecution: (data.isSuccessful ? "Attempted" : "Cancelled"), id: $('#Id').val() }; $.ajax({ type: 'POST', url: urlToPost, data: data, success: function (result) { alert(result.Message); }, error: function () { v2RegularNotice('fail'); } }); }); $('#uploadButton').live('click', function () { theThing = kw.get("<%=SlickUpload1.ClientID %>"); v2RegularNotice('click me'); theThing.submit(); }); }
this combined with the custom model binder found here:http://krystalware.com/blog/archive/2010/02/27/modelbinder-asp.net-mvc-uploadstatus-controller-action-method.aspx
lets you have a controller action like this:
public function ChangePhoto(byval status as UploadStatus, byval id as integer) as actionresult
and status is properly populated.
so basically, it just needed to have:
kw_uploadExecution: (data.isSuccessful ? "Attempted" : "Cancelled"),
that part added.
support thread can be found here:http://krystalware.com/forums/yaf_postsm5128_aspnet-mvc-ajax-upload-without-update-panel.aspx#post5128