Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: ValidationMessageFor Not Displaying Razor/MVC5

$
0
0
I have successfully integrated FluentValidation into my MVC5 project. One of the simpler rules in my validator class is:
RuleFor(x => x.DisplayName)
    .NotEmpty()
    .WithLocalizedMessage(() => SharedResources.VALIDATOR_REQUIRED);
VALIDATOR_REQUIRED is set to "{PropertyName} Required". In my view, I have a Validation Summary and this:
<div class="editor-field">
    @Html.EditorFor(m => m.DisplayName)
    @Html.ValidationMessageFor(m => m.DisplayName)
</div>
Which becomes
<div class="editor-field">
        <input name="DisplayName" class="text-box single-line" id="DisplayName" type="text" value="">
        <span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="DisplayName"></span>
    </div>
When I submit with a blank DisplayName, the validation summary has the text "Display Name Required" as expected, but the validation message does not show up next to the editor.

Any suggestions on what I'm doing incorrectly here? I noticed that FluentValidation automatically inserted a space "DisplayName", which is great for the validation summary. Any chance that is messing up the individual validator?

Thanks.

Viewing all articles
Browse latest Browse all 1917

Trending Articles