开发者

MVC - Access Model Error Messages in Control template

开发者 https://www.devze.com 2023-03-05 11:41 出处:网络
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=\

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号