【问题标题】:jqgrid - upload a file in add/edit dialogjqgrid - 在添加/编辑对话框中上传文件
【发布时间】:2011-11-24 21:42:38
【问题描述】:

我是 jqgrid 的新手,通过你的回答我学到了很多东西。
现在我有一个问题:我想在向 jqgrid 添加或修改记录时上传文件?

这是我的代码:

{
    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找到了一个很好的例子

【问题讨论】:

  • 您的链接使我进入了一个这样的页面,我没有找到任何线索,因为您告诉我这是一个很好的例子。
  • 在 ASP.NET MVC 中下载 jqGrid – 编辑、TinyMCE、上传 (tpeczek.codeplex.com/releases/view/63305)。这是一个工作版本

标签: javascript jquery jqgrid


【解决方案1】:

我昨天才开始工作..这是我用于文件上传的 colModel 列,

{
    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

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

【讨论】:

  • 为什么要在afterSubmit事件中添加?谢谢!
  • 我正在 UploadImage 函数中准备就绪状态:0,响应文本:"",状态:0,状态文本:"错误"。有什么想法吗?
  • 您没有编写自定义格式formatter: jgImageFormatter的代码。另请提及您在解决方案中使用的 fileUpload 库的链接。当前链接已失效
  • 此解决方案将使用新的图像名称再次更新数据库?
猜你喜欢
  • 1970-01-01
  • 2013-08-06
  • 2011-09-23
  • 1970-01-01
  • 2011-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多