I have form, where users can adds dynamically few people to form. How to get all people from form, make objects from them and add them to table. Next I make json and send it via ajax to controller in ASP.NET MVC C# application.
-
Your question is too broad. But what you can do is, create input elements with names matching to your viewmodel property names (which you use as the parameter of your httppost action method) and serialize the form (jQuery serialize method) and send it via ajax.Shyju– Shyju2017-03-22 14:28:25 +00:00Commented Mar 22, 2017 at 14:28
-
Here is the link to js file I'm talking about paweljanicki.pl/rozne/umowa-inna.jsPaweł Janicki– Paweł Janicki2017-03-22 14:39:56 +00:00Commented Mar 22, 2017 at 14:39
-
Please provide all relevant code in an minimal reproducible example in the question itself, not only on a third-party site.Heretic Monkey– Heretic Monkey2017-03-22 15:00:08 +00:00Commented Mar 22, 2017 at 15:00
-
You can refer to the answer here stackoverflow.com/questions/2145012/… (dynamically add row)pinkfox– pinkfox2017-03-23 07:45:03 +00:00Commented Mar 23, 2017 at 7:45
Add a comment
|
1 Answer
I don't know if I understand your problem, but you can do something similar below:
- Create an JS object where you save your "people" added at your form
- For each "people" added, edited or removed (for ex.) update a model hidden field with JSON value [JavaScript JSON.stringfy(yourObject)]
- Then, when your form is submited, you can use JsonConvert c# class to deserialize your string an "People" object instance.
Or if you want to use something without JavaScript and more appropriate, you can look at this post > MVC BegginCollectionItem Example