简体   繁体   中英

User defined validation

I would like to kwnow if it possible for users to add validation rules at runtime. I have a system that will be sold to clients that could be anywhere in the world. So in some countries certain fields is required and in other those fields are not required. So i thought I would add functionality so that when i implement the system, the fields that needs to be validated could be set by me, without the need to add the data-annotations to the properties, then recompile the entire system.

It will be an ASP.NET MVC application using Entity Framework

regards

You can do this in the following way

  1. Use data-annotations with the properties
  2. And while using the annotation check on your view there you can check which country it is by using a simple if else condition, and show the checks only at the required country views

     if(someCondition) { @Html.ValidationMessageFor(model => @Model.User.Username) } 

尝试fluentvalidation http://fluentvalidation.codeplex.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM