Frage

I am implementing Uploadify to upload files to a server which works perfectly. but i have come into some problems when i want to write the response to the a model in my view...

Lets say i have a customer model with a headshot field that i want to populate with the response from the Uploadify 'oncomplete' event...

whats the best practice to do something like this.. I'm quite new to web dev so i've found myself very lost trying to figure this out..

cheers in advance for any help

War es hilfreich?

Lösung

If I am understanding you correctly, you want to populate the model from the 'successful' response from uploadify callback?

What I usually do is:

  • Upload the image using the uploadify plugin
  • I have separate controller which uploadify talks to
  • Save it, resize it, and maybe do other adjustments to the actual image itself on the server
  • The server will return either a success message or failed message
  • If a failed message is returned, the server returns the failed message, together with the error
  • If a success message is returned, the server will return the success message together with the path of the image
  • On the callback I will use jQuery to populate my models hidden field with the path of the image.

If you want an example, or if you have any other questions, just let me know.

Thanks

Tyrone

Edited ----------

Lets say I have a view which contains the following

 @Html.HiddenFor(model => model.Media.Path, new { @id = "image-path" });
 <input type="file" name="imageFile" id="file-upload" />

My script contains the following

$('#file-upload').uploadify({

    'uploader': '/Scripts/Admin/uploadify/uploadify.swf',

    'script': '/Admin/Media/UploadImage/',

    'cancelImg': '/uploadify/cancel.png',

    'auto': true,

    'fileExt': '*.jpg;*.gif;*.png;*.pdf',

    'sizeLimit': 202400000,

    'onComplete': function (event, ID, fileObj, response, data) {
        $("#image-path").val(response);
     }

});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top