0

Lets say I have about 200 hidden fields. They have a name with three subdivisions (from, to), (foo, bar) and (guid). Eg.:

@Html.Hidden("from_foo_87985c5a-86a8-4b7d-bc13-6858d00ed806", "1")
@Html.Hidden("to_bar_87985c5a-86a8-4b7d-bc13-6858d00ed806", "0")

@Html.Hidden("from_foo_0c3320ac-fee8-4752-889a-d6894829432b", "2")
@Html.Hidden("to_bar_0c3320ac-fee8-4752-889a-d6894829432b", "0")

@Html.Hidden("from_foo_c76eaa3e-ea7b-4074-bf8a-3bef98c93062", "1")
@Html.Hidden("to_bar_c76eaa3e-ea7b-4074-bf8a-3bef98c93062", "0")

@Html.Hidden("from_foo_d6570707-03cc-4223-b31c-2b1ecca5039d", "0")
@Html.Hidden("to_bar_d6570707-03cc-4223-b31c-2b1ecca5039d", "1")

In my C# Controller I can get all those fields with a FormCollection to work with this. But I'm pretty sure there is a better way. I thought about a Dictionay like this:

Dictionary<string, Dictionary<Guid, int>>

...but I have no idea how to do it nor it's a good idea.

Werner
  • 2,126
  • 2
  • 22
  • 34

1 Answers1

0

I am wondering why you are not using Strongly typed Datatype i.e. Sending Model from view in Controller. This is the most effective and recommended way.

Take a look at below link, this might help you a little bit View to Controller in mvc3

Community
  • 1
  • 1
Nipun Ambastha
  • 2,553
  • 1
  • 16
  • 26
  • This is because this page is a little bit too complex. I have to write in those hidden-fields because it depends on clicks on some div-elements. And when a div got clicked a javascript will run, calculating and write the value in a specific hidden-field. – Werner Aug 08 '13 at 05:25