1) Let's say I've this form:
<% Using(Html.BeginForm()) { %>
<%= Html.Hidden("myObject",
(cast to the appropriate type)ViewData["KeyForMyObject"] %>
<input type = "submit" "Submit Object">
<% } %>
2) Here's the Action which's supposed to intercept the value of the object
public ActionResult MyAction(Type myObject)
{
//Do Something with the object
}
Here's my question: What type of objects the Hidden field can support?
In fact, when ViewData["KeyForMyObject"] contains a string, int, or bool, myAction is able to retrieve the value.
But, when it comes to objects, such as List, and dictionary, nothing happens. When I debug to check the local values, I see null for Type myObject in the MyMethod.
So what are the rules in MVC when it comes to a List or Dictionary?
EDIT
To make things simpler, can I write something like this
<%= Html.Hidden("contactDic", (Dictionary<string, string>)ViewData["contacts"]) %>
and expect to retrieve the dictionary in the action Method like this
public ActionResult myMethod(Dictionary<string, string> contactDic)
{
// Do something with the dictionary
}
Thanks for Helping