fluentvalidation

Validating a list of objects - unobtrusively ASP.NET MVC 3 C#

烂漫一生 提交于 2020-01-06 14:07:46
问题 This seem like it should be easy to implement but I am finding it challenging. I have a list of objects in my view model that need to be validated, unobtrusively. I have looked at FluentValidation for this yet there seems to be a bug in the collections validation implementation that does not fire the unobtrusive validator. Not sure if there is a way to use Data Annotations for a list of objects where the validation will happen unobtrusively (and server-side) I am looking for suggestions on

Validating a list of objects - unobtrusively ASP.NET MVC 3 C#

痞子三分冷 提交于 2020-01-06 14:07:14
问题 This seem like it should be easy to implement but I am finding it challenging. I have a list of objects in my view model that need to be validated, unobtrusively. I have looked at FluentValidation for this yet there seems to be a bug in the collections validation implementation that does not fire the unobtrusive validator. Not sure if there is a way to use Data Annotations for a list of objects where the validation will happen unobtrusively (and server-side) I am looking for suggestions on

re-using ServiceStack validation in Winforms offline client

喜你入骨 提交于 2020-01-04 15:15:54
问题 We have a working website using ServiceStack as the back end that amounts to a complex data-entry form. My users have requested an "offline editor" for the forms. To use the offline program, the user will have to connect to the ServiceStack service, create empty instances of the forms, and then I will save the POCOs from the service to disk using ServiceStack's JSON serializer. From there the user can log off the service and edit the POCOs. When they're done, they reconnect to the service,

How to perform async ModelState validation with FluentValidation in Web API?

筅森魡賤 提交于 2020-01-01 12:27:11
问题 I setup a web api project to use FluentValidation using the webapi integration package for FluentValidation. Then I created a validator that uses CustomAsync(...) to run queries against the database. The issue is that the validation seems to deadlock when awaiting for the database task. I did some investigation, it seems that the MVC ModelState API is synchronous, and it calls a synchronous Validate(...) method that makes FluentValidation to call task.Result , causing the deadlock. Is it

FluentValidation.AspNetCore is not working in Class Library

寵の児 提交于 2020-01-01 12:04:08
问题 I am using library "FluentValidation.AspNetCore": "6.4.0-beta3" in .netcore WebApi in a project. You can see the project structure below. Library is working fine if i place the CurrencyDTO.cs code in section 2 (Project FH.WebAPI) and if the same code placed in section 1 (Class Library DTO) its not working. And requirement is that i have to place code in Class library FH.Common . Is there any work around.I have search but didn't find any thing Project Structure CurrencyDTO.cs [Validator(typeof

Fluent Validation in MVC: specify RuleSet for Client-Side validation

允我心安 提交于 2019-12-30 18:42:12
问题 In my ASP.NET MVC 4 project I have validator for one of my view models, that contain rules definition for RuleSets. Edit ruleset used in Post action, when all client validation passed. Url and Email rule sets rules used in Edit ruleset (you can see it below) and in special ajax actions that validate only Email and only Url accordingly. My problem is that view doesn't know that it should use Edit rule set for client html attributes generation, and use default rule set, which is empty. How can

Can Fluent Validation .NET determine error messages sequence

点点圈 提交于 2019-12-25 01:09:03
问题 I use Fluent Validation .NET for validating. Is it possible to determine error messages sequence from "RuleFor" in validation summary. Example: RuleFor(x=>x.A).NotEmpty().WithMessage("A is required."); RuleFor(x=>x.B).NotEmpty().WithMessage("B is required."); For example, How can I determine message sequence to specificly show "B is required." before "A is required". 回答1: There is no explicit ordering of rules inside FluentValidationModelValidationFactory validator queries, that means that

How to validate uploaded files by FluentValidation

喜你入骨 提交于 2019-12-24 17:10:31
问题 How can I validate uploaded files using FluentValidation? <input type="file" asp-for="Files" multiple /> 回答1: your ViewModel must have public IList<IFormFile> Files { get; set; } : public class CustomViewModel { public IList<IFormFile> Files { get; set; } ... } you must create a validator for IFormFile type as below: public class FileValidator : AbstractValidator<IFormFile> { public FileValidator() { RuleFor(x => x.Length).NotNull().LessThanOrEqualTo(100) .WithMessage("File size is larger

fluentvalidation change default error message for int/long

拟墨画扇 提交于 2019-12-24 00:04:54
问题 Is there a way to change the default error message for an in in FluentValidation? We are able to set up validations for more complex types but the simple 'the data you entered isn't an int' style things we can't seem to get at. The built in error for these is: 'the value x isn't valid for y' or something along those lines - is there a way to override these? 回答1: There's no easy/clean way to achieve that. The first possibility is to override the DefaultModelBinder.ResourceClassKey property in

How to validate collection items using RuleForEach

纵然是瞬间 提交于 2019-12-23 12:17:37
问题 I have been using (successfully) the following validation: RuleFor(x => x.Items) .SetCollectionValidator(new ItemValidator()) .Must(coll => coll.Sum(item => item.Percentage) == 100) .When(x => x.Items != null); As the above SetCollectionValidator is (will be) deprecated, I changed it to: RuleForEach(x => x.Items) .SetValidator(new ItemValidator()) .Must(coll => coll.Sum(item => item.Percentage) == 100) .When(x => x.Items != null); However, Sum is not recognized anymore. How can I fix this?