1

I have a very large form that represents a month or more of data. Each day has 3 drop-downs the user can update and then i need to save the data in the form. I should mention I had to make a custom dropdown (HERE) to use a style class so it's not the standard Html.dropdown()

So what I'd like to do is something like...

View:

    @{

        List<string> DropdownValues = new List<string>();

    }

    @using(Html.BeginForm("Method","Controller",FormMethod.Post,new{ Data = DropdownValues}))
    {
      @Html.CustomDropdown("Name1",ListOfOptions1)
      @Html.CustomDropdown("Name2",ListOfOptions2)
      @Html.CustomDropdown("Name3",ListOfOptions3)

      <input type="submit" value="Submit" />
      @{
         //Do on submit 
         DropdownValues.add(Name1.value);
         DropdownValues.add(Name2.value);
         DropdownValues.add(Name3.value);

      }
    }

Ideas?

Thanks!

1 Answer 1

2

You can access form element direct from controller code without them having to be part of the Action parameters. Maybe this is what you are looking for?...

//In controller post action

string name1 = Request.Form["Name1"];
string name2 = Request.Form["Name2"];
//etc...

You could even put it in a loop depending on what you are doing with the data...

for(int i = 1; i <= 30; i++)
{
   string nameX = Request.Form["Name" + i];
}
Sign up to request clarification or add additional context in comments.

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.