Denmark Puso

Denmark Puso

  • 1.7k
  • 203
  • 9.7k

how to pass from.serilize() and array value using ajax?

May 22 2020 10:19 AM

im using serialize to pass the value of 'form' from ajax to controller. the problem is my 'test' array is null didnot pass the value from ajax to controller im using mvc5. please help thanks

but when i removed the model form the test array has a value and pass into controller. i need both parameter to pass into controller
  1.     var test = [];  
  2.     test[0] = 1;  
  3.     test[1] = 2;  
  4.     function saveSelected() {  
  5.         var model = $('form').serialize();  
  6.   
  7.          $.ajax({  
  8.             url: '@Url.Action("index", "payment")',  
  9.             type: 'POST',  
  10.             data: { model: model.serialize(), test: test },  
  11.             traditional: true,  
  12.             success: function (data) {  
  13.                 alert("success");  
  14.             }  
  15.         });  
  16.     }  
 My Controller 
  1. public ActionResult Index(MyModel model, string[] test)  
  2.     {return View();}

Brought to you by:

Answers (11)