0

depending on configuration at each site, some fields on a form may or may not be required. Can I apply the [Required] attribute to fields of my ViewModel in code? I'd like to take advantage of all the conveniences of form validation, but I can't hard-code the [Required] attribute.

2 Answers 2

1

Checkout FluentValidation.NET. It could be used as a replacement of Data Annotations and has great integration with ASP.NET MVC. It allows you to define dynamic validation rules based on runtime conditions.

Sign up to request clarification or add additional context in comments.

Comments

0

No.* Metadata is cooked into the assembly.

*(Well I guess you could emit the assembly at runtime but lord that would be alot of crazy work)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.