Today (January 15, 2010) Scott posted a blog on ASP.NET MVC2 model validation
http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx
Does anyone know how someone can add validation rules at runtime programmatically?
"Programmatic Registration" is similar functionality supported by ValidationAspects
// register lambda syntax validation functions typeof(User).GetProperty("Name").AddValidation<string>((name, context) => { if (!Exists(name)) { throw new ValidationException("Username is unknown"); } } ); // register validation factories (classes) typeof(User).GetProperty("Name").AddValidation(new [] { new NotNullOrEmpty()} ); // don't like strings? TypeOf<User>.Property(user => user.Name).AddValidation(new [] { new NotNullOrEmpty()} );
To provide custom metadata, you have to implement the abstract ModelMetadataProvider class and register it inside your global.asax:
ModelMetadataProviders.Current = new ConventionMetadataProvider();
. ModelMetadata, HTML.EditorFor.
, . .
. . , . .
Source: https://habr.com/ru/post/1728672/More articles:Silverlight 4 and real 3d support - silverlightASP.NET MVC: best way to return an AjaxRequest type? - jqueryWhen to add an index to joined tables - joinRepresentation of errors in client-server transmission - javaMySQL select query Ошибка - mysqlCKEditor plugin documentation - pluginsIs_a predicate definition in prolog? - inheritanceКак изменить способ отображения фильтров и столбцов внешнего ключа на сайте DynamicData? - c#быстрое перечисление на NSDictionary завершается с ошибкой "[Waypoint countByEnumeratingWithState: objects: count:]: непризнанный селектор, отправленный экземпляру..." - objecthtml 4.0 in XPATH requests - xpathAll Articles