I'm trying to add a CSS class to a textbox when validation fails.
@Html.TextBoxFor(x => x.AdminUser.Username, new
{
@id = "Username",
@name = "Username",
@type = "text",
@class = "form-control",
@placeholder = "Kullanıcı Adı",
@autocomplete = "off"
})
@Html.ValidationMessageFor(x => x.AdminUser.Username, null, new { @class = "text-danger text-12 pl-10" })
Is it possible to add a callback to it? Or anyway else?
Solution for me:
Overriding onError class of unobtrusive validation source js did the trick. Now I can able to access upper div element.
if (replace) {
container.empty();
error.removeClass("input-validation-error").appendTo(container);
error.closest("div").addClass("has-error");
}