fluentvalidation

FluentValidation: Check if one of two fields are empty

荒凉一梦 提交于 2019-11-28 22:05:03
问题 I have this model public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } I want to create a validation where either FirstName or LastName must be filled in by user. I installed FluentValidation and created a customvalidator class public class PersonValidator:AbstractValidator<Person> { public PersonValidator() { RuleFor((person=>person.FirstName)//don't know how to check if one is empty } } To check just one field I could

Validate checkbox on the client with FluentValidation/MVC 3

这一生的挚爱 提交于 2019-11-28 20:44:21
I am trying to validate if a check box is checked on the client using FluentValidation. I can't figure it our for the life of me. Can it be done using unobtrusive validation? Let's assume that you have the following model: [Validator(typeof(MyViewModelValidator))] public class MyViewModel { public bool IsChecked { get; set; } } with the following validator: public class MyViewModelValidator : AbstractValidator<MyViewModel> { public MyViewModelValidator() { RuleFor(x => x.IsChecked).Equal(true).WithMessage("Please check this checkbox"); } } and a controller: public class HomeController :

How to hook FluentValidator to a Web API?

夙愿已清 提交于 2019-11-28 17:29:38
I'm trying to hook Fluent Validation to my MVC WEB Api project, and it doesn't wanna work. When I use MyController : Controller -> works fine ( ModelState.IsValid returns False ) but when I use MyController :ApiController ... nothing. Does anyone have experience on how to hook those up ? latest version of Fluent Validation (5.0.0.1) supports web api Just install it from Nuget and register it in Global.asax like so: using FluentValidation.Mvc.WebApi; public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { ... FluentValidationModelValidatorProvider

How to validate Date in ClientSide using FluentValidation?

自古美人都是妖i 提交于 2019-11-28 08:45:00
Question The below code is working fine Server side and not Client side. Why ? When I submit the form, control goes to BeAValidDate function to check the date is valid or not. Is there any way to Validate the date without going to server using Fluent Validation ? Scripts <script src="jquery-1.7.1.min.js" type="text/javascript"></script> <script src="jquery.validate.js" type="text/javascript"></script> <script src="jquery.validate.unobtrusive.js" type="text/javascript"></script> Model public class PersonValidator : AbstractValidator<Person> { public PersonValidator() { RuleFor(x => x.FromDate)

Fluent Validations. Error: Validation type names in unobtrusive client validation rules must be unique

我只是一个虾纸丫 提交于 2019-11-28 07:37:34
I got the erorr: Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required. The following validation type was seen more than once: required I used server validation. And all worked fine. But now I`m stating to use client-side validation and I got this problem. This is my validation class code: public class TestViewDataValidation : BaseTestCreateViewDataValidation<BaseTestCreateViewData> { public TestViewDataValidation () { this.RuleFor(x => x.Login).NotNull(); this.RuleFor(x => x.Login).NotEmpty(); this.RuleFor

Fluent Validation vs. Data Annotations [closed]

二次信任 提交于 2019-11-28 03:07:27
What are the operative differences between these two validation packages when used for ASP.NET MVC validatation? They seem to have similar objects, all the way to their object names. Is one related to another? What are their differences? In what way do these differences denote different use cases? Fluent Validation (3rd party solution) Data annotations (Microsoft "baked-in") Darin Dimitrov I prefer Fluent Validation : It gives me far better control of my validation rules Doing conditional validation on different properties is so much easier compared to Data Annotations It separates the

Validate checkbox on the client with FluentValidation/MVC 3

♀尐吖头ヾ 提交于 2019-11-27 20:45:23
问题 I am trying to validate if a check box is checked on the client using FluentValidation. I can't figure it our for the life of me. Can it be done using unobtrusive validation? 回答1: Let's assume that you have the following model: [Validator(typeof(MyViewModelValidator))] public class MyViewModel { public bool IsChecked { get; set; } } with the following validator: public class MyViewModelValidator : AbstractValidator<MyViewModel> { public MyViewModelValidator() { RuleFor(x => x.IsChecked).Equal

unobtrusive client validation using fluentvalidation and asp.net mvc LessThanOrEqualTo not firing

て烟熏妆下的殇ゞ 提交于 2019-11-27 10:04:29
I have the following rules the 1st does work using unobtrusive, client side validation, the second does not any ideas why? RuleFor(x => x.StartDate) .LessThanOrEqualTo(x => x.EndDate.Value) .WithLocalizedMessage(() => CommonRes.Less_Than_Or_Equal_To, filters => CommonRes.Start_Date, filters => CommonRes.End_Date); RuleFor(x => x.StartDate) .GreaterThanOrEqualTo(x => x.AbsoluteStartDate) .LessThanOrEqualTo(x => x.AbsoluteEndDate) .WithLocalizedMessage(() => CommonRes.Between, filters => CommonRes.Start_Date, filters => filters.AbsoluteStartDate, filters => filters.AbsoluteEndDate); Darin

How to validate Date in ClientSide using FluentValidation?

﹥>﹥吖頭↗ 提交于 2019-11-27 02:24:47
问题 Question The below code is working fine Server side and not Client side. Why ? When I submit the form, control goes to BeAValidDate function to check the date is valid or not. Is there any way to Validate the date without going to server using Fluent Validation ? Scripts <script src="jquery-1.7.1.min.js" type="text/javascript"></script> <script src="jquery.validate.js" type="text/javascript"></script> <script src="jquery.validate.unobtrusive.js" type="text/javascript"></script> Model public

Fluent Validation vs. Data Annotations [closed]

浪尽此生 提交于 2019-11-26 23:57:37
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . What are the operative differences between these two validation packages when used for ASP.NET MVC validatation? They seem to have