Fluent Validation â ïž
A small validation library for .NET that uses a fluent interface and lambda expressions for building validation rules. ð«
NuGet Packages :
For ASP.NET MVC integration :
For ASP.NET Core :
ð¹ðžð¹ðž
Example :
ð¹ðžð¹ðž
https://t.me/pgimg/78
[ Github ] : http://bit.do/flval
ã°ã°ã°ã°ã°ã°
#CSharp #AspMvc #Validation
@ProgrammingTip
A small validation library for .NET that uses a fluent interface and lambda expressions for building validation rules. ð«
NuGet Packages :
Install-Package FluentValidation
For ASP.NET MVC integration :
Install-Package FluentValidation.MVC5
For ASP.NET Core :
Install-Package FluentValidation.AspNetCore
ð¹ðžð¹ðž
Example :
public class PersonValidator : AbstractValidator<Person>
{
public PersonValidator()
{
RuleFor(x => x.ID).NotEmpty();
RuleFor(x => x.FirstName)
.NotEmpty()
.WithMessage("{PropertyName} is required !")
.MinimumLength(5)
.WithMessage("Minimum length for {PropertyName} is {MinLength} !");
RuleFor(x => x.LastName)
.NotEmpty()
.WithMessage("{PropertyName} is required !")
.MinimumLength(5)
.WithMessage("Minimum length for {PropertyName} is {MinLength} !");
RuleFor(x => x.Email)
.NotEmpty()
.WithMessage("{PropertyName} is required !")
.EmailAddress()
.WithMessage("{PropertyName} is not valid !");
}
}
ð¹ðžð¹ðž
https://t.me/pgimg/78
[ Github ] : http://bit.do/flval
ã°ã°ã°ã°ã°ã°
#CSharp #AspMvc #Validation
@ProgrammingTip
Telegram
Programming Tips Resources
ASP.NET Core 2 â Global Model Validation â ïž
We use a lot of repetitive code in our actions. â»ïž
Inside of our controller actions we usually check if the model is valid by using ModelState property available on MVCâs base controller class :
The bad thing about is that we repeat this piece of code throughout a lot of our actions. â
How we can make it betterâ
This article shows you how to validate ModelState with a global filter. ð
https://t.me/pgimg/112
[ Article ] : bit.do/mval
ã°ã°ã°ã°ã°ã°
#AspMvc #Core #Validation
@ProgrammingTip
We use a lot of repetitive code in our actions. â»ïž
Inside of our controller actions we usually check if the model is valid by using ModelState property available on MVCâs base controller class :
if (!ModelState.IsValid)
return BadRequest(ModelState);
The bad thing about is that we repeat this piece of code throughout a lot of our actions. â
How we can make it betterâ
This article shows you how to validate ModelState with a global filter. ð
https://t.me/pgimg/112
[ Article ] : bit.do/mval
ã°ã°ã°ã°ã°ã°
#AspMvc #Core #Validation
@ProgrammingTip
Telegram
Programming Tips Resources
Superstruct ð¥
A simple and composable way to validate data in Javascript. âš
Superstruct makes it easy to define interfaces and then validate JavaScript data against them. â ïž
Its type annotation API was inspired by Typescript, Flow, Go, and GraphQL, giving it a familiar and easy to understand API. ð§
But Superstruct is designed for validating data at runtime, so it throws (or returns) detailed runtime errors for you or your end users. ð¥
This is especially useful in situations like accepting arbitrary input in a REST or GraphQL API, but it can even be used to validate internal data structures at runtime when needed. â
[ Github ] : kutt.it/SprStr
ã°ïžã°ïžã°ïžã°ïžã°ïžã°ïž
#JavaScript #Validation
@ProgrammingTip
A simple and composable way to validate data in Javascript. âš
Superstruct makes it easy to define interfaces and then validate JavaScript data against them. â ïž
Its type annotation API was inspired by Typescript, Flow, Go, and GraphQL, giving it a familiar and easy to understand API. ð§
But Superstruct is designed for validating data at runtime, so it throws (or returns) detailed runtime errors for you or your end users. ð¥
This is especially useful in situations like accepting arbitrary input in a REST or GraphQL API, but it can even be used to validate internal data structures at runtime when needed. â
[ Github ] : kutt.it/SprStr
ã°ïžã°ïžã°ïžã°ïžã°ïžã°ïž
#JavaScript #Validation
@ProgrammingTip
Telegram
Programming Tips Resources