0

I generate my views genericly with reflection so I am wondering if it is possible to get the validation attributes for all the properties of a class and then make them show in the view if there is a violation

For example:

public class Person 
{
    [Range(0,300)]
    [Required(ErrorMessage ="Please provide a weight")]
    public double Weight { get; set; }
}
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Glanie
  • 17
  • 4
  • Does this answer your query - https://stackoverflow.com/questions/7027613/how-to-retrieve-data-annotations-from-code-programmatically – Sai Gummaluri Aug 17 '20 at 12:46
  • Thank you for your reply! Sadly, this answers only part of my query, I'm also wondering how I could display the error near the specific input field value, do you have any links on that? :-) – Glanie Aug 17 '20 at 13:05
  • Take a look at this - https://stackoverflow.com/a/18965540 If this is not working out, will take a look at implementing something custom. – Sai Gummaluri Aug 17 '20 at 15:03

0 Answers0