views:

34

answers:

2

anybody knows how to transform the FormCollection into a IDictionary or how to get a IDictionary in the post action ?

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
+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
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