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.

4
  • 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. Commented Mar 22, 2017 at 14:28
  • Here is the link to js file I'm talking about paweljanicki.pl/rozne/umowa-inna.js Commented 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. Commented Mar 22, 2017 at 15:00
  • You can refer to the answer here stackoverflow.com/questions/2145012/… (dynamically add row) Commented Mar 23, 2017 at 7:45

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.