I want to do the following.
- Pass a complex json object in a hidden input variable
- Get that hidden variable through the form collection object.
- Convert that hidden text value to a dynamic object which I can loop through to
get the data from it
So I think the first two items above I can do.
- $(“#hiddenVariableID”).val(JSON.stringify(data));
- Have a parameter called FormCollection collection in the MVC controller.
Then get the value the following way String data =
collection.Get(“hiddenVariableID”); - ?? Not sure how to do this.
The data I’m passing is an array of objects. The objects are never the same so that is why I need to convert the results in some type of dynamic object that I can loop through.
I can’t do an ajax call to do this because I want to stream down the data passed in the hidden variable. So it has to be through a form submission.
Thank you,
-Tesh
You can at that point use some JSON parser to convert between the string and a JSON object you can access dynamically. There are many JSON parsers out there, the code below shows how it can be done with two of them: the JavaScriptSerializer (part of the .NET Framework), and the JSON.NET (a non-MS library, but which IMO is really good).