anybody knows how to transform the FormCollection
into a IDictionary
or how to get a IDictionary
in the post action ?
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]);
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);
}
On .Net Core this one worked for me.
var collection = Request.Form.Keys.ToDictionary(k => k, v => Request.Form[v].ToString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With