c# - Passing List of objects by appending it in jquery formdata -


i came across scenario in mvc 4 need send image along list of objects in ajax call. how can append in formdata? here formdata , ajax call

    var formdata = new formdata();     var imgfile = document.getelementbyid('profilepic');     var imgfilelist = imgfile.files;     formdata.append(imgfilelist[0].name, imgfilelist[0]);      // below code not workin     formdata.append('rent', $scope.renttypes);     // $scope.renttype = [{ id:1,price:5},{id:2,price:6}]          $.ajax({             url: url             data: formdata,             processdata: false,             contenttype: false,             type: 'post'         }); 

in controller, action called ajax call this

  public actionresult upload(list<rent> rent) { } 

rent.cs

public class rent {  public int id;  public int price;  public available; } 

in order post collection, need construct data indexers can bound defaultmodelbinder

.... formdata.append('[0].id', 1); formdata.append('[0].price', 5); formdata.append('[1].id', 2); formdata.append('[1].price', 6);  $.ajax({   url: url   data: formdata,   processdata: false,   contenttype: false,   type: 'post' }); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -