-
-
Notifications
You must be signed in to change notification settings - Fork 10
Custom view model validators
Alexanderius edited this page Jun 7, 2024
·
3 revisions
Model validators work in the same way as binders.
To use custom model validator you should register it using HttpModelHandler.RegisterModelValidator
, it will be added to validators pipeline.
HttpModelHandler.RegisterModelValidator<MyModelValidator>();
DIContainer.Current.Register<MyModelValidator>(LifetimeType.Singleton);
Validator should be deriver from IModelValidator
interface.
public class MyModelValidator : IModelValidator
{
public void Validate<T>(T model)
{
// Validation logic
}
}
If you just want to use your validator without default validators, then you should clear validators list first.
HttpModelHandler.ModelValidatorsTypes.Clear();
HttpModelHandler.RegisterModelValidator<MyModelValidator>();
}
- Getting Started
- Main Simplify.Web principles
- Simplify.Web controllers
- Simplify.Web views
- Simplify.Web templates
- Simplify.Web configuration
- Templates variables
- Static content
- Template factory
- Data collector
- String table
- File reader
- Web context
- Environment
- Dynamic environment
- Language manager
- Redirector
- HTML