Sending data from dynamic list – ASP.NET Core MVC.

Send dynamic list to controller

Today I’ll show you how to add items to dynamic list and then send values to controller. In the first step, let’s create simple web page based on Bootstrap and JQuery. Assume that we make a recipe for the cake. From combobox we choose some piece and we put the amount into the textbox that is next to it, then add them to the recipe list . For the impatient it looks so.

My script to add elemenets look likes as below.

That script add elements to the list depending on whether it is a value from a combo-box or a textbox.In addition if position already exist then we add values to the existing list.To not make a mess on the list. An importat element – if we want to send dynamic list to controller we need to set value name like name=”[0].Name”. This tell us that is zero(first) element on list.

This is important when we removing items from dynamically list.

As you can see I remove element from list and then I rearrange the elements. Because when we let list with [0].Name and [2].Name and send this list to controller, it will send only first element from our list because he doesn’t see the next([1].Name).

 To post values from our dynamic table we just need to pack it in the form like :

HERE you can see effect without send values to controller.

Confirmation that it works in ASP.NET Core MVC below. 🙂
dynamic list
Link to the project: HERE

One Comment on “Sending data from dynamic list – ASP.NET Core MVC.”

Leave a Reply

Your email address will not be published. Required fields are marked *