开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜