2011-09-26 69 views
6

我是jqgrid的新手,我通過你的回答學到了很多東西。
現在我有一個問題:我想在向jqgrid添加或修改記錄時上傳文件?

這是我的代碼:

jqgrid - 在添加/編輯對話框中上傳文件

{ 
    name: 'File', 
    index: 'file', 
    hidden: true, 
    enctype: "multipart/form-data", 
    editable: true, 
    edittype: 'file', 
    editrules: { 
     edithidden: true, 
     required: true 
    }, 
    formoptions: { 
     elmsuffix: '*' 
    } 
} 



但是我在控制了總是爲空:(領域的任何建議
任何人都提前知道工作示例
謝謝

UPDATE
我在http://tpeczek.codeplex.com/releases

中發現了一個很好的例子
+2

您的鏈接使我在一個這樣的頁面發送給我,我沒有發現任何線索,因爲您告訴我們它是一個很好的例子。 – Tareq

+0

下載ASP.NET MVC中的jqGrid - 編輯,TinyMCE,上傳(http://tpeczek.codeplex.com/releases/view/63305)。這是一個工作版本 – Dranix

回答

5

我得到它的工作只是yesterday..here是我的文件上傳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。它只在數據已經過後&回覆後才上傳文件。我在這裏檢查,如果插入是succesfful然後只開始上傳其他顯示錯誤。我用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!'); 
      } 
     } 
    )   }                        
+0

爲什麼它在afterSubmit事件中添加?謝謝! –

+0

我在UploadImage函數中準備好了狀態:0,responseText:「」,status:0,statusText:「error」。有任何想法嗎? – mikemike396

+1

您沒有編寫自定義格式'formatter:jgImageFormatter'的代碼。另外請提及您在解決方案中使用的fileUpload庫的鏈接。目前的鏈接已經死機 – sohaiby

相關問題