question

dncoso avatar image
0 Votes"
dncoso asked Viorel-1 answered

Asp.net : table that i want to collect values from and add to empty input to a form

I have an asp.net core MVC app which I have a form with some fields in a table.

On the same page, with JavaScript, I generate rows and cells to an existing table that is not in the same as my form.

On post in my form I want to collect the values generated from my javascript code and the other table and pass this along with my post as a new list.

Can I create a hidden input inside my form and for each over the JavaScript populated table? Or should it be done in another way?

dotnet-csharpdotnet-aspnet-core-mvc
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Is there any way you can share the source code so the community can see what you're trying to do? Explain the expected results and actual results.

0 Votes 0 ·

Hi @dncoso ,
Sorry, through your descriptions, I am not sure what you need to achieve. Can you share your code so that it can help you better.

0 Votes 0 ·

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

Maybe collect the data from your rows using JavaScript and obtain a JSON string, which can be put to your hidden field. Then use the System.Text.Json package on client side (added using “Manage NuGet Packages”) to convert the string to objects.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

Thanks for the answer!

I solved it according to your suggestion.

Jsonstringify JavaScript in the view

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

And JSONserializer in the asp.net api

https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializer?view=net-5.0

0 Votes 0 ·