Trying to remove a particular error from c# ModelState using linq but not successful..
Linq not working/removing items but no error:
ModelState.Values.ToList().ForEach(u =>
{
if (u.Errors.Any())
{
u.Errors.ToList().RemoveAll(z =>
z.ErrorMessage == "Exceeded allowed chars");
}
});
Working one:
foreach (var s in ModelState.Values)
{
foreach (var e in s.Errors.ToList())
{
if (e.ErrorMessage == "Exceeded allowed chars")
s.Errors.Remove(e);
}
}
Why the above linq not removing error item? what I'm missing? Possible to avoid ToList() in linq to avoid performance penalty?