How to upload multiple images to SQL Server using JSON in ASP.Net MVC?

I need to insert a set of information into the SQL Server Database data, but along with them some photos along with some strings. I'm wanting to move everything by JSON.

Input to select the image:

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

As step to JSON (not going well until I changed the first sfoto1InputFile to be able to load, but it didn't work out):

<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>
Author: Maniero, 2014-09-05

1 answers

I would use the plugin jQuery File Upload .

Example of how to use it with ASP.NET MVC.

Now, correcting your example, I believe an exchange of $.getJSON by $.post(); passing the proper parameters.

 2
Author: Thiago Custodio, 2014-09-06 00:17:35