Last post Mar 22, 2019 12:19 PM by Yuki Tao
Mar 21, 2019 07:48 PM|brucey|LINK
Hi everyone, I'm trying to display an error message with image, but receiving null error.
I'm using FluentValidation
System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Web.Mvc.Html.ValidationExtensions.ValidationMessageFor<TModel, TProperty>(...) returned null
@Html.Raw(HttpUtility.HtmlDecode(@Html.ValidationMessageFor(m => m.IsVehicleDetailsCorrect).ToHtmlString()))
RuleSet("IsVehicleDetailsCorrect", () =>
RuleFor(x => x.IsVehicleDetailsCorrect)
.WithMessage("<i class='icon-warning'></i>Please confirm if vehicle details are correct");
Everything works ok if I call the validation like this, but I would like to include image, any points much appreciated...
@Html.ValidationMessageFor(m => m.IsVehicleDetailsCorrect)
Mar 22, 2019 12:19 PM|Yuki Tao|LINK
According to your requirement,I do not suggest you add image in FluentValidation.
It is difficult to parse code.
If you would like to add image,I suggest you could use css,like:
background-size: 16px 16px;
But This makes span text contents dissapear and instead places background-image in there. This gives pretty close visual behavior to one you need.
More details ,you could refer to this link: