0

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

2 Answers 2

1
  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 .

Sign up to request clarification or add additional context in comments.

6 Comments

On number 2 - do you mean to do "@model ViewModel"? I did that, now, inside my @using (Html.BeginForm()) {} I have 2 textboxes, and the Create ActionResult gets (ViewModel model). But once I run the website and fill the textboxes, nothing is passed to the ActionResult. Any ideas why?
yes, you need to create and bind your view with RecipeViewModel.
your Create ActionResult will gets (RecipeViewModel model)
Worked out GREAT!! I think I'll manage from here. I made a few Lists in the RecipeViewModel that get all the recipe properties, now, once I pass them to the controller, I can "Unwrap" the lists and bind them together myself.
Cigano, What does the BeginCollectionItem exactly do?
|
0

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.