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

Was it helpful?

Solution

  1. Add a ViewModel class:

    public class RecipeViewModel
    {

      public string ReceipeName {get; set;}
    
      public List<string> ingredients {get; set;}
    

    }

  2. Bind your view to this ViewModel

  3. Now use Jquery/Javascript to give user facility to add ingredients .

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:

https://www.nuget.org/packages/BeginCollectionItem/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top