Reputation: 1825
I'm creating a website with asp.net, mvc 4 and c# and currently have a problem I did not find a solution online for.
I have a rather complex CREATE-form which includes a dropdown-list with the values 1-7 and a list of textboxes. To this list of textboxes I can add more textboxes via JavaScript so the amount of textboxes is not limited right now.
Moreover, if I select any value in the dropdown-list - let's say value 5 - the list of textboxes appears 5 times.
To handle the undetermined amount of textboxes, each textbox in such a list gets the same name with an index per list. To give an example: in the first list of textboxes, they are all named textbox-1, in the second list they have the name textbox-2, etc.. I hope you get where I'm going with this.
My Problem now: I would like to have a model with 7 lists of strings which get populated with the values from the respective textboxes. Maybe I didn't really know what to look for (because honestly I didn't) but I could not find anything similar on Google.
The only solution that I could think of would be to not use a model and just use the form collection but that feels like it would destroy any purpose and advantage of the mvc framework. But maybe there is also a completely different approach to this problem that totally slipped my mind.
I hope I could you guys can even understand what I'm talking about.. kinda hard to explain. If not I'm sure you'll let me know :-)
Upvotes: 0
Views: 65
Reputation: 129546
I would go ahead and treat this one-off with the form querying. No sense in bending the framework.
If you do want to go the route of the model, you need to make a model that encapsulates the maximum number of text boxes. Have your javascript give ids and names to the textboxes that will reflect your model's naming.
Upvotes: 1