Reputation: 1875
I know that we can clear values of all fields by ModelState.Clear(). But what if I'd like to clear only a field, such as incorrect security image code, and all the other fields will remain same.
Any helps will be much appreciated.
Upvotes: 0
Views: 54
Reputation: 634
You can do something like this:
if (!ModelState.IsValidField(key))
{
var emptyValue = new ValueProviderResult(
string.Empty,
string.Empty,
CultureInfo.CurrentCulture);
ModelState.SetModelValue(
key,
emptyValue);
}
Upvotes: 2