Domanda

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);

È stato utile?

Soluzione

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");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top