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();}
Jaimin ShethiyaPosted May 25, 2020, 4:49 AM
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
Salman BegPosted May 25, 2020, 1:55 AM
Denmark PusoPosted May 25, 2020, 1:52 AM
Salman Beg
Salman BegPosted May 23, 2020, 7:40 AM
Denmark PusoPosted May 23, 2020, 7:35 AM
Jaimin ShethiyaPosted May 22, 2020, 10:52 PM
you can try this line and checked the value is getting or not.
data: { model: model.serialize(), test: test.serialize() },
Thanks
Jaimin ShethiyaPosted May 22, 2020, 10:48 PM
you can use the JSON.stringify(model);
var model = {
name: "abc",
gender: "M"
};
for example: JSON.stringify(model);
Thanks
Denmark PusoPosted May 22, 2020, 7:50 PM
Salman Beg
Salman BegPosted May 22, 2020, 10:54 AM
Denmark PusoPosted May 22, 2020, 10:36 AM
Salman BegPosted May 22, 2020, 10:31 AM