ASP.NET – How to post form with dynamically added html elements?

Share on WhatsApp
Share via email Share

Let us assume that you’re creating a page in ASPX where you’re dynamically adding some HTML elements under a parent on a button click. You can do this easily through JQuery. But how do you get these dynamically added fields from HTML table in your C# controller?

Suppose you have a table and the added row has the following columns.

If more rows like above are added in a table, then how will you read above text boxes? You give a common ‘name’ attribute to all the input text fields with same value you like:

For 2 rows with same name attribs like above:

Now you simply post the form and this would be the controller part:

You can use IEnumerable when you’re posting multiple things with the same type. Like multiple usernames, phone numbers, marks, product names, etc. Then convert them to a List and iterate through them. Do your logic and make great apps!

Thank you.


Share on WhatsApp
Share via email Share

Leave a Reply

Your email address will not be published.