FAQ Database Discussion Community


Client-side unobtrusive validation for EditorTemplate when sending IEnumerable

asp.net,asp.net-mvc,unobtrusive-validation,fluentvalidation,mvc-editor-templates
There is a possibility that I just wasn't able to find the solution, or lack thereof, through my searches. Maybe I didn't word it properly, but my problem is trying to get client-side unobtrusive validation to fire on an EditorTemplate when I pass an IEnumerable<T> to it. My setup: ParentModel.cs...

FluentValidation, is possible an inline validation?

c#,validation,fluentvalidation
I have a the following operation: public void Save (Customer c, IEnumerable <Product> products) {     // Validate that you have entered at least one product.     if (!produtos.Any()) throw new ArgumentOutOfRangeException("products"); } Inline, without using inheritance (eg AbstractValidator ), as would this same operation using the FluentValidation library?...

FluentValidation not working for a null property

c#,wpf,fluentvalidation,idataerrorinfo
I'm using FluentValidation with IDataErrorInfo, and I have a validator defined as follows: public class StsInfoValidator : AbstractValidator<StsInfo> { public StsInfoValidator() { RuleFor(x => x.SomeProperty).Cascade(CascadeMode.StopOnFirstFailure) .NotNull().NotEmpty().WithMessage("SomeProperty is required."); } } However, passing in a null property doesn't seem to trigger the validator: #region IDataErrorInfo public string this[string columnName] { get...

How to add a non-property rule in FluentValidation?

c#,fluentvalidation
I have this validator class: internal class CustomerTypeValidator : AbstractValidator<CustomerType> { public CustomerTypeValidator() { RuleFor(x => x.Number).Must(BeANumber).WithState(x => CustomerTypeError.NoNumber); } private bool BeANumber(string number) { int temp; bool ok = int.TryParse(number, out temp); return ok && temp > 0; } } And I have the service class: public class CustomerTypeService...

ASP.Net MVC TextBoxFor ignore my format

c#,asp.net-mvc,html-helper,fluentvalidation
I create some helper method and create TextBoxFor inside it. input.AppendLine(html.TextBoxFor(expression, format, attributes).ToString()); My format was "{0:dd/MM/yyyy}". It's work totally fine and render as <input class="form-control req" data-val="true" data-val-date="The field detr must be a date." id="detr" name="detr" type="text" value="25/05/2558" /> But when ModelState has error on this field, TextBoxFor was...

FluentValidation NotEmpty and EmailAddress example

c#,validation,refactoring,fluentvalidation
I am using FluentValidation with a login form. The email address field is Required and Must be a valid email address. I want to display a custom error message in both cases. The code I have working is: RuleFor(customer => customer.email) .NotEmpty() .WithMessage("Email address is required."); RuleFor(customer => customer.email) .EmailAddress()...

Fluent Validation ensuring a list has at least one item with property value of somevalue

asp.net-mvc,fluentvalidation
Assume I have the following viewmodel: public class TaskViewModel{ public MTask Task {get;set;} public List<DocIdentifier> Documents {get;set;} ..... } public class DocIdentifier{ public string DocID {get;set;} public bool Selected {get;set;} } And here's the Fluent Validation validator I use: public class TaskValidator : AbstractValidator<TaskViewModel>{ public TaskValidator{ } } How can...

Simple Injector “The operation cannot be completed because the DbContext has been disposed” during MVC validation

.net,asp.net-mvc,entity-framework,fluentvalidation,simple-injector
I have a pretty complicated problem. I'm using FluentValidation.MVC in my ASP.NET MVC 5 project. In it, I use a repository pattern to check whether a user's email address is not duplicated. The issue isn't really the repository pattern; it's that the repository uses an Entity Framework context injected into...

FluentValidation - How to customize the validation message in runtime

c#,validation,message,fluentvalidation
In this entity: public class Foo { public Guid Id { get; set; } public string Type { get; set; } public string Name { get; set; } } How can I customize the validation message in runtime using another property of entity or any other string obtained from the...

How can I use multiple regex expressions with different validation messages

asp.net-mvc,validation,asp.net-mvc-5,passwords,fluentvalidation
Requirements I want to check password policies by using multiple regex expressions. For each policy violation I want to display a specific validation message. Examples: You need to use at least 2 numbers You need to use at least one upper and one lower case letter You need to use...

FluentValidation Chain Properties Validation Issue

c#,wpf,validation,chaining,fluentvalidation
I've just implemented INotifyDataErrorInfo using JeremySkinner's FluentValidation. However I have some difficulties with validation of complex properties. For example, I would like to validate Nationality property: RuleFor(vm => vm.Nationality.SelectedItem.Value) .NotEmpty() .Length(0, 255); However, this great looking peace of code has two major problems: 1) it throws null reference exception when...

Best approach for Client-side validation for each custom rule in FluentValidation

c#,asp.net-mvc,asp.net-mvc-4,unobtrusive-validation,fluentvalidation
I am using FluentValidation in my Asp.Net MVC 4 application. I have already known that some rules are automatically generating attributes for jQuery validation library. And this script library has already known what it must check for example in case of data-rule-required, data-rule-range and so on. I know that there...

Generic covariance with Simple Injector and Fluent Validation

c#,fluentvalidation,simple-injector,contravariance
I'm building a query pipeline (using the decorator pattern for an IQueryHandler) in which, before the query is actually executed, a number of cross-cutting concerns is handled. One of these concerns is validation, for which I'm using the Fluent Validation Library. Simple Injector is the IoC container of choice and...

FluentValidation in Lightinject

c#,model-view-controller,inversion-of-control,fluentvalidation,light-inject
I'm using fluentvalidation and lightinject Here is my code to insert a blog article; public OperationResultDto Add(BlogArticleDto blogArticleDto) { OperationResultDto result = new OperationResultDto(); ValidationResult validationResult = _blogArticleModelValidator.Validate(blogArticleDto); if (!validationResult.IsValid) { result.IsOk = false; ValidationFailure firstValidationFailer = validationResult.Errors.FirstOrDefault(); if (firstValidationFailer != null) { result.Message = firstValidationFailer.ErrorMessage; } return result; }...