0

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 Mar 22 '17 at 14:28
  • Here is the link to js file I'm talking about http://paweljanicki.pl/rozne/umowa-inna.js – Paweł Janicki Mar 22 '17 at 14:39
  • Please provide all relevant code in an [mcve] in the question itself, not only on a third-party site. – Heretic Monkey Mar 22 '17 at 15:00
  • You can refer to the answer here http://stackoverflow.com/questions/2145012/adding-rows-dynamically-with-jquery (dynamically add row) – pinkfox Mar 23 '17 at 07:45

1 Answers1

0

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

Community
  • 1
  • 1
m.lucas
  • 169
  • 6