Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ASPNET MVC 4、ajaxFileUpload和Webpi使用Jqgrid上载文件_Jqgrid_Asp.net Web Api_Jqgrid Asp.net_Jqgrid Php - Fatal编程技术网

使用ASPNET MVC 4、ajaxFileUpload和Webpi使用Jqgrid上载文件

使用ASPNET MVC 4、ajaxFileUpload和Webpi使用Jqgrid上载文件,jqgrid,asp.net-web-api,jqgrid-asp.net,jqgrid-php,Jqgrid,Asp.net Web Api,Jqgrid Asp.net,Jqgrid Php,我无法使用()使上载工作,但无法使其工作。我正在跟踪,但是没有调用UploadImage函数。我的意思是,似乎事后调查事件并没有被触发 你知道为什么吗 jQuery("#ajaxGrid").jqGrid({ url: $("#ServiceUrl").val(), datatype: "json", jsonReader: { repeatitems: false, id: "Id" },

我无法使用()使上载工作,但无法使其工作。我正在跟踪,但是没有调用UploadImage函数。我的意思是,似乎事后调查事件并没有被触发

你知道为什么吗

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

提前谢谢!吉列尔莫。

我已经解决了! 我有两个问题: 1) 在浏览器中查看开发人员工具时,我可以看到有两种可能的请求操作。我将文件上载操作移动到一个单独的webapi控制器,解决了这个问题。 2) 由于我在下面使用FileUpload,所以FileUpload列的名称没有被采用(没有大写)

谢谢!吉列尔莫