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
- var test = [];
- test[0] = 1;
- test[1] = 2;
- function saveSelected() {
- var model = $('form').serialize();
- $.ajax({
- url: '@Url.Action("index", "payment")',
- type: 'POST',
- data: { model: model.serialize(), test: test },
- traditional: true,
- success: function (data) {
- alert("success");
- }
- });
- }
- public ActionResult Index(MyModel model, string[] test)
- {return View();}

Salman BegRank #284 · 8.8K reputationPosted May 22, 2020, 6:31 AM EDT
Denmark PusoRank #7,130 · 248 reputationPosted May 22, 2020, 6:36 AM EDT
Salman BegRank #284 · 8.8K reputationPosted May 22, 2020, 6:54 AM EDT
Denmark PusoRank #7,130 · 248 reputationPosted May 22, 2020, 3:50 PM EDT
Salman Beg
Jaimin ShethiyaRank #177 · 13.7K reputationPosted May 22, 2020, 6:48 PM EDT
you can use the JSON.stringify(model);
var model = {
name: "abc",
gender: "M"
};
for example: JSON.stringify(model);
Thanks
Jaimin ShethiyaRank #177 · 13.7K reputationPosted May 22, 2020, 6:52 PM EDT
you can try this line and checked the value is getting or not.
data: { model: model.serialize(), test: test.serialize() },
Thanks
Denmark PusoRank #7,130 · 248 reputationPosted May 23, 2020, 3:35 AM EDT
Salman BegRank #284 · 8.8K reputationPosted May 23, 2020, 3:40 AM EDT
Denmark PusoRank #7,130 · 248 reputationPosted May 24, 2020, 9:52 PM EDT
Salman Beg
Salman BegRank #284 · 8.8K reputationPosted May 24, 2020, 9:55 PM EDT
Jaimin ShethiyaRank #177 · 13.7K reputationPosted May 25, 2020, 12:49 AM EDT
can you make it an another class ad in that two property and that is used class in you api.
hope that will work for you.
Ideally when use post api then generally used single parameter.
below the example
In controller side
Thanks