Here are 3 ways to get your values with a FormCollection object.
public ActionResult SomeActionMethod(FormCollection formCollection)
{
//Cycling through the AllKeys
foreach (var key in formCollection.AllKeys)
{
var value = formCollection[key];
}
//By Each Key
foreach (var key in formCollection.Keys)
{
var value = formCollection[key.ToString()];
}
// Using the ValueProvider
IValueProvider valueProvider = formCollection.ToValueProvider();
foreach (string key in formCollection.Keys)
{
ValueProviderResult result = valueProvider.GetValue(key);
string value = result.AttemptedValue;
}
}
Comments