MVC - Access Model Error Messages in Control template
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 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
精彩评论