Add a ViewModel class:
public class RecipeViewModel
{public string ReceipeName {get; set;} public List<string> ingredients {get; set;}
}
Bind your view to this ViewModel
Now use Jquery/Javascript to give user facility to add ingredients .
How send unknown number of inputs texts into create action in MVC?
-
12-10-2022 - |
Question
In my Create View, I have a form that the user decides how many objects to add to the database. Lets say the DB is for a Recipe site, so in add recipe you will have 1 textbox for RecipeName, but the number of ingredients change from one recipe to another, so I let the user add textboxes with Jquery. now, after the user presses the submit button, I want to manually get the Querystring and order them by the inputbox name.
my question is how do I get the Querystring in the create action?
I tried to use the Request.QueryString[], but it returns null.
thanks in advance, Nimi
Solution
OTHER TIPS
I think it's the case to use BeginCollectionItem
:
MVC 3 Dynamic Form Using a ViewModel
It is available in NuGet as a package:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow