2014-09-01 58 views
0

我需要在數據庫sqlserver數據中插入一組信息,但隨着它們一些圖片以及一些字符串。我想要通過Json移動所有內容。上傳多個圖像到sqlserver使用json mvc asp.net

下面

是輸入選擇圖像

<th> 
     <div class="form-group"> 
      <label for="legendaFoto5">Legenda</label> 
      <input type="text" class="form-control" id="legendaFoto5" placeholder="Legenda da Foto"> 
     </div> 
    </th> 

低於這個部分,我一起到JSON通過,暫時不順利,直到我改變了第一個「sfoto1InputFile」要能上傳,但它不起作用。

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#salvarLevantamentoFicha").click(function (evt) { 
      var sfoto1InputFile = $("#foto1InputFile").get(0).files[0]; 
      var sfoto2InputFile = $("#foto2InputFile").image; 
      var sfoto3InputFile = $("#foto3InputFile").image; 
      var sfoto4InputFile = $("#foto4InputFile").image; 
      var sfoto5InputFile = $("#foto5InputFile").image; 

      var strlegendaFoto1 = $("#legendaFoto1").val(); 
      var strlegendaFoto2 = $("#legendaFoto2").val(); 
      var strlegendaFoto3 = $("#legendaFoto3").val(); 
      var strlegendaFoto4 = $("#legendaFoto4").val(); 
      var strlegendaFoto5 = $("#legendaFoto5").val(); 
      $.getJSON("@Url.Content("~/CadLevantamentoAmbiental/SalvarFichaLevantamentoTC")", { 
       _sfoto1InputFile: sfoto1InputFile, 
       _sfoto2InputFile: sfoto2InputFile, 
       _sfoto3InputFile: sfoto3InputFile, 
       _sfoto4InputFile: sfoto4InputFile, 
       _sfoto5InputFile: sfoto5InputFile, 
       _strlegendaFoto1: strlegendaFoto1, 
       _strlegendaFoto2: strlegendaFoto2, 
       _strlegendaFoto3: strlegendaFoto3, 
       _strlegendaFoto4: strlegendaFoto4, 
       _strlegendaFoto5: strlegendaFoto5     
      }); 

     }); 
    }); 
</script> 

回答

1

ypu必須考慮幾件事情,以及瀏覽器之間的幾個區別。所以,你能做的最好是使用和現有的完成這件事jQuery插件,例如:

第二個是一個更通用的解決方案,報包含它包含的文件上傳的整個表單。

如果你試圖自己做,而不使用插件,你會遇到很大的麻煩。