Denmark Puso

Denmark Puso

  • 1.7k
  • 203
  • 9.6k

ajax other parameter is null?

May 14 2020 2:44 AM
why my other paramter is null. "date" and "ids" is null while my "postedFile" and "amount" has a data. but when i try to removed "postedFile" parameter. the ids and date has a value. and it works fine. but i need the postedfile parameter
 
my script
  1. var ids = [];    
  2. function add(id, isChecked) {    
  3.     if (isChecked) {    
  4.         ids.push(id);    
  5.     }    
  6.     else {    
  7.         var i = ids.indexOf(id);    
  8.         ids.splice(i, 1);    
  9.     }    
  10. }    
  11.     
  12. function saveSelected() {    
  13.     //var shipmentId = $('#c-shipment-id').val();    
  14.     var date = $('#Date').val();    
  15.     var amount = $('#Amount').val();    
  16.     //var ImageFile = $('#imageUploadForm').val();    
  17.     
  18.     $('#imageUploadForm').on("change"function () {    
  19.         var formdata = new FormData($('form').get(0));    
  20.         CallService(formdata);    
  21.     });    
  22.     
  23.     function CallService(postedFile) {    
  24.         $.ajax({    
  25.             url: '@Url.Action("index", "payment")',    
  26.             type: 'POST',    
  27.             data: { ids: ids, amount: amount, date: date, postedFile: postedFile },    
  28.             cache: false,    
  29.             processData: false,    
  30.             contentType: false,    
  31.             traditional: false,    
  32.             dataType:"json",    
  33.             success: function (data) {    
  34.                 alert("Success");    
  35.             }    
  36.         });    
  37.     }    
  38. }   
My controller
  1. public ActionResult Index(int?[] ids, decimal? amount, DateTime? date, HttpPostedFileBase postedFile)
  2. {  
  3.     return View();  
  4. }

Brought to you by:

Answers (13)