This should still work. The first argument to AddModelError
is the key. You're passing it the value of the property Username
.. which won't work. What you want is to pass the property name as the key:
ModelState.AddModelError("Username", "Invalid Username provided.");
// ^^^^^^^^^^ Username property of model
Of course this must be coupled with a ValidationSummary
or ValidationMessage
in your view.