Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I made a an HTML form which has some input elements on it- say name, country. I have another table which displays food preferences. when the user adds a food preference, they are added to an array/JSON in the background (using javascript) and displayed in the table.
Posting only the form to server is Ok, but posting both the form and the array of preferences is difficult for me. I'm using asp.net core. What am I doing wrong? thanks

What I have tried:

I tried using jquery ajax but the array is not sent to the server. null is always sent.
Posted
Updated 22-Mar-19 5:23am
v2
Comments
Mohibur Rashid 21-Mar-19 17:22pm    
Source code please

1 solution

Here's a logic you should be able to reuse often:

When you generate your JSON, use the DOM to store it in your form. Now it will go to the server with the remainder of the form's data.
HTML
<include type='hidden' name='json' id='json' value='the JSON data string'>
You can do lots of nice things with the hidden input element.
 
Share this answer
 
Comments
Richard Deeming 22-Mar-19 12:41pm    
That element name should be input, not include. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900