سؤال

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

هل كانت مفيدة؟

المحلول

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");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top