Question

Assume that I cannot add annotation of requierd to some filed in the model.

there is a way to raise and error from the controller to this specific field on the right side of the field like if I use annotation...

currently I use which put the error on top of the screen.

ModelState.AddModelError("", "User field is required);

Was it helpful?

Solution

Use the same call, but replace the first parameter with the property name as a string you want to attach the error to:

ModelState.AddModelError("MyFieldWithError", "This is the error message");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top