anybody knows how to transform the FormCollection into a IDictionary or how to get a IDictionary in the post action ?
views:
34answers:
2
+1
Q:
asp.net-mvc get a dictionary in post action or how to transform FormCollection into a dictionary
A:
I did it like this:
var form = new Dictionary<string, string>();
foreach (var key in formCollection.AllKeys)
{
var value = formCollection[key];
form.Add(key, value);
}
Omu
2010-05-04 12:37:47
+1
A:
This is just an equivalent of Omnu's code, but it seems more elegant to me:
Dictionary<string, string> form = formCollection.AllKeys.ToDictionary(k => k, v => formCollection[v]);
Trimack
2010-05-04 12:44:36
I think it's a matter of style, i personally think Omu's code is a little more verbose, but it's easier to see what happens.
Michel
2010-05-04 12:48:49