1

( ajaxFileUpload )を使用してアップロードを機能させることはできませんが、機能させることはできません。この投稿をフォローしていますが、UploadImage関数が呼び出されていません。つまり、afterSubmitイベントは発生していないようです。

なぜ何かアイデアはありますか?

jQuery("#ajaxGrid").jqGrid({
    url: $("#ServiceUrl").val(),
    datatype: "json",
    jsonReader: { repeatitems: false, id: "Id" },
    colNames: ['Id', 'logoTarjeta'],
    colModel: [
        { name: 'Id', index: 'id', editable: false, sortable: true, hidden: true, align: 'left' },
        {
            name: 'FileToUpload', index: 'logo', editable: true, edittype: 'file',
            editoptions: {
                enctype: "multipart/form-data"
            },
            width: 210, align: 'center', /*formatter: jgImageFormatter,*/ search: false
        }
    ],
    prmNames: { nd: null, search: null, page: "pageNumber", rows: "pageSize", sort: "sortColumn", order: "sortDirection" },
    mtype: 'GET',
    rowNum: 15,
    pager: '#ajaxGridPager',
    rowList: [10, 20, 50, 100],
    imgpath: $("#ServiceImagesUrl").val(),
    multiselect: false,
    scrollOffset: 0,
    afterSubmit: UploadImage,
    error: function (x, e) {
        alert(x.readyState + " " + x.status + " " + e.msg);
    }
});

function updateDialog(action) {
    return {
        url: $("#ServiceUrl").val(),
        closeAfterAdd: true,
        closeAfterEdit: true,
        afterShowForm: function (formId) { },
        modal: true,
        onclickSubmit: function (params) {
            var list = $("#ajaxGrid");
            var selectedRow = list.getGridParam("selrow");
            params.url += "/" + list.getRowData(selectedRow).Id;
            params.mtype = action;
        },
        width: "400",
        ajaxEditOptions: { contentType: "application/json" },
        serializeEditData: function (data) {
            delete data.oper;
            return JSON.stringify(data);
        }
    };
}

jQuery("#ajaxGrid").jqGrid(
    'navGrid',
    '#ajaxGridPager',
     {
         add: true,
         edit: true,
         del: true,
         search: false,
         refresh: false
     },
     updateDialog('PUT'),
     updateDialog('POST'),
     updateDialog('DELETE')
);

$(window).resize(resize_the_grid);

function resize_the_grid() {
    $('#ajaxGrid').fluidGrid({ base: '#grid_wrapper', offset: -20 });
}

function UploadImage(response, postdata) {
    debugger;
    var data = $.parseJSON(response.responseText);

    if (data.success == true) {
        if ($("#fileToUpload").val() != "") {
            ajaxFileUpload(data.id);
        }
    }
    return [data.success, data.message, data.id];
}

function ajaxFileUpload(id) {
    $("#loading")
    .ajaxStart(function () {
        $(this).show();
    })
    .ajaxComplete(function () {
        $(this).hide();
    });

    $.ajaxFileUpload(
        {
            url: $("#UploadImageUrl").val(),
            secureuri: false,
            fileElementId: 'fileToUpload',
            dataType: 'json',
            data: { id: id },
            success: function (data, status) {
                if (typeof (data.success) != 'undefined') {
                    if (data.success != true) {
                        return alert(data.message);
                    }
                    return true;
                } else {
                    return alert('Failed to upload logo!');
                }
            },
            error: function (data, status, e) {
                return alert('Failed to upload logo!');
            }
        }
    );
}

これは送信時に呼び出されるwebapiサービスです

public HttpResponseMessage Put(Type type)
        {
            if (ModelState.IsValid)
            {
                Uow.Types.Update(type);
                Uow.Commit();
                var resp = new HttpResponseMessage
                {
                     Content = new StringContent("{\"success\":true,\"message\":\"\",\"new_id\":\"\"}")
                };
                resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                //resp.StatusCode = HttpStatusCode.NoContent;
                return resp; 
            }

            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }

そして、プラグインのjavascriptがWebページにロードされているのがわかります。

前もって感謝します!ギレルモ。

4

1 に答える 1

0

解決しました!2つの問題がありました。1)ブラウザで開発者ツールを確認すると、リクエストに対して2つの可能なアクションがあることがわかりました。ファイルアップロードアクションを別のwebapiコントローラーに移動し、その問題を修正しました。2)以下のfileUploadを使用していたため、FileUpload列の名前が使用されていませんでした(大文字ではありません)。

ありがとう!ギレルモ。

于 2013-01-25T02:28:50.547 に答える