I appear to have missed something very simple, but can't find the answer anywhere.
I want to generate a generic "You've got errors -- see below" type of statement atop a form when any errors exist using @Html.ValidationSummary(true)
, and list all the specific errors only inline next to the relevant fields. I want the logic and the error text contained in an Action Filter.
The problem is, all the documentation I've seen on "model-level" errors explains how to display them in views, but not how to add them to the model state.
Errors added via ModelState.AddModelError
are not model-level - so how can I do I add a model-level error?
ModelState.AddModelError
will work. Just set the key with an empty string.
ModelState.AddModelError(String.Empty, "here is the error");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With