Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net-mvc get a dictionary in post action or how to transform FormCollection into a dictionary

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

like image 925
Omu Avatar asked May 04 '10 11:05

Omu


3 Answers

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]);
like image 164
Trimack Avatar answered Dec 28 '22 05:12

Trimack


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);
            }
like image 21
Omu Avatar answered Dec 28 '22 05:12

Omu


On .Net Core this one worked for me.

var collection = Request.Form.Keys.ToDictionary(k => k, v => Request.Form[v].ToString());
like image 22
Jaime Torner Avatar answered Dec 28 '22 05:12

Jaime Torner