jqgrid - upload a file in add/edit dialog(jqgrid - 在添加/编辑对话框中上传文件)
问题描述
我是 jqgrid 的新手,通过你的回答我学到了很多东西.
现在我有一个问题:我想在jqgrid中添加或修改记录时上传文件?
这是我的代码:
I'm new to jqgrid and I have learn many things through your answer.
 
Now I have a problem: I want to upload files when adding or modifying records to a jqgrid?
This is my code:
{
    name: 'File',
    index: 'file',
    hidden: true,
    enctype: "multipart/form-data",
    editable: true,
    edittype: 'file',
    editrules: {
        edithidden: true,
        required: true
    },
    formoptions: {
        elmsuffix: '*'
    }
}
但是我在控制器中得到的字段始终为空:(.任何建议
有人知道工作示例吗?
提前致谢
更新
我在 http://tpeczek.codeplex.com/releases
推荐答案
我昨天才开始工作..这是我用于文件上传的 colModel 列,
I got it working just yesterday..here's my colModel column for file upload,
{
    name: 'fileToUpload',
    index: 'customer_id',
    align: 'left',
    editable: true,
    edittype: 'file',
    editoptions: {
        enctype: "multipart/form-data"
    },
    width: 210,
    align: 'center',
    formatter: jgImageFormatter,
    search: false
}
您必须设置 afterSubmit: UploadImage.它仅在数据发布后才上传文件&反应回来了.我在这里检查,如果插入成功,则仅开始上传,否则显示错误.我用过 Jquery Ajax File Uploader.
You have to set afterSubmit: UploadImage. It uploads the file only after data has been post & response has come back. I'm checking here that if insert was succesfful then only start upload else show error. I've used Jquery Ajax File Uploader.
function UploadImage(response, postdata) {
    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: '@Url.Action("UploadImage")',
            secureuri: false,
            fileElementId: 'fileToUpload',
            dataType: 'json',
            data: { id: id },
            success: function (data, status) {
                if (typeof (data.success) != 'undefined') {
                    if (data.success == true) {
                        return;
                    } else {
                        alert(data.message);
                    }
                }
                else {
                    return alert('Failed to upload logo!');
                }
            },
            error: function (data, status, e) {
                return alert('Failed to upload logo!');
            }
        }
    )          }                                                                                            
                        这篇关于jqgrid - 在添加/编辑对话框中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jqgrid - 在添加/编辑对话框中上传文件
				
        
 
            
        基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
 - 每次设置弹出窗口的焦点 2022-01-01
 - jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
 - Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
 - 如何使用 CSS 显示和隐藏 div? 2022-01-01
 - Node.js 有没有好的索引/搜索引擎? 2022-01-01
 - 如何在特定日期之前获取消息? 2022-01-01
 - 什么是不使用 jQuery 的经验技术原因? 2022-01-01
 - 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
 - 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				