I am trying to make my custom template for textbox in MVC 3. How can I access ErrorMessage in the template, which I specified with an attribute in model (e.g. [Required(ErrorMessage="Some error message")] ?
I am trying to make my custom template for textbox in MVC 3. How
Share
I believe you need to access the metadata, cast it to a required attribute and reference the errormessage property.
To access the metadata – use ViewData.ModelMetadata in your template.
See:
http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-4-custom-object-templates.html