1

完全に機能するサーバーにファイルをアップロードするために Uploadify を実装しています。しかし、ビューでモデルへの応答を書きたいときに、いくつかの問題が発生しました...

Uploadifyの「oncomplete」イベントからの応答を入力したいヘッドショットフィールドを持つ顧客モデルがあるとしましょう...

このようなことを行うためのベストプラクティスは何ですか..私はWeb開発にまったく慣れていないので、これを理解しようとして非常に迷っていることに気づきました..

助けを求めて事前に乾杯

4

1 に答える 1

1

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);
     }

});
于 2011-12-13T06:38:08.117 に答える