I have a very complex form in a web page. User actually builds up a complex object. The UI is handled using jQuery (showing, hiding sections, duplicating and deleting sub-forms,...).
Simply posting the form upon user submission, although possible, doesn't seem the best solution: It would be hard to makeup unique names for fields (there can be arrays of objects) and to decode the whole stuff on server side.
I guess I should rather post a JSON representation of the object. How do I do that?
I'm not trying to make an ajax call. I want to submit the form but using JSON instead of an usual application/x-www-form-urlencoded form.
FWIW, the backend is ASP.NET MVC.
TIA,
Serialise to JSON using script...
Although this answer uses Ajax, you could instead write the serialised string to an input[type=hidden] in your form
Serializing to JSON in jQuery
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With