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

Commented Issue: Validation rules are not triggered [7117]

$
0
0
Hello,

this is my code I have setup:

public class ReleaseViewModelValidator : AbstractValidator<ReleaseViewModel>
{
public ReleaseViewModelValidator()
{
RuleFor(r => r.Name).NotEmpty().Length(1, 30).WithMessage("Name must not be longer than 30 chars.");
}
}

[FluentValidation.Attributes.Validator(typeof(ReleaseViewModel))]
public class ReleaseViewModel
{
public int ReleaseId { get; set; }
[Remote("ReleaseExists", "Release", ErrorMessage = "This name already exists.")]
public string Name { get; set; }
public DateTime CreatedAt { get; set; }
}

GlOBAL.ASAX:
FluentValidationModelValidatorProvider.Configure();

VIEW:
model ILMD.Web.Models.ReleaseViewModel

@* Remote Validation*@
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm("Create", "Release"))
{
<p class="editor-label">@Html.LabelFor(model => model.Name)</p>
<p class="editor-field">@Html.EditorFor(model => model.Name)</p>
<p class="editor-field">@Html.ValidationMessageFor(model => model.Name)</p>
}

All my unit tests for the ReleaseViewModelValidator show green light. Fine.

But less cool is that entering some live data like 31 chars or entering nothing I do not see any client side error message.

Do I still have to include something in my partial view? The ModelState is also not correct, thus I am updating my database with null values....crash...bom...bang...

Can you help me please?
Comments: Is MVC's client-side validation enabled? Can you see the data-* attributes being generated in your mark-up?

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>