Asp.net-mvc gets dictionary in post action or how to convert FormCollection to dictionary

Does anyone know how to convert FormCollection to IDictionary or how to get IDictionary in post action?

+4
source share
3 answers

This is just the equivalent of Omnu code, but it seems more elegant to me:

Dictionary<string, string> form = formCollection.AllKeys.ToDictionary(k => k, v => formCollection[v]); 
+9
source

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); } 
0
source
  public static IDictionary<string, string[]> GetFormParameters(FormCollection collection) { IDictionary<string, string[]> formParameters = new Dictionary<string, string[]>(); foreach (var key in collection.AllKeys) { if (key == null) continue; var value = collection.GetValues(key); // value = CrossSiteAttackUtil.CleanHtml(value); if (value != null) { formParameters.Add(key, value); } } 
0
source

Source: https://habr.com/ru/post/1014558/


All Articles