Is there a nice linqy way of splitting a FormCollection
into a Dictionary
that contains only those keys that start wi
[HttpPost]
public ActionResult Index(FormCollection collection)
{
Dictionary<string,object> form = new Dictionary<string, object>();
collection.CopyTo(form);
return View();
}
If you're looking for a "nice" way of taking an existing dictionary, producing a new dictionary with copies of keys+values, for a subset of the keys, some LINQ code will do this nicely:
var appSettings = formCollection.AllKeys
.Where(k => k.StartsWith("AppSettings."))
.ToDictionary(k => k, k => formCollection[k]);