Hello,
Let's say I have this property
[Required(ErrorMessage = "Add this property")]
public string MyProperty {get; set;}
When I use modelbinding validation like this
UpdateModel(myModel);
Then when there is an error the form is re-displayed, and the textbox representing MyProperty is highlighted (i.e. red borders and pink background). The Html.ValidateMessageFor() display also error message next to the textbox.
But, when I do it manually, like this
if(string.NullOrEmpty(myModel.MyProperty))
ModelState.AddModelError("MyProperty", "Custom message");
If there's an error, I still get the error message. But only Html.ValidationSummary()) displays list of error on top of the page. But the texbox is not highlighted anymore and the Html.ValidateMessageFor() doesn't display anything at all.
Is there anything I can do to fix that?
Thanks for helping.