开发者

Template for ValidationMessage

MVC now contains a lot of stuff that you can ovrride using templates, you could override UI representation of any model's field based on any rule and its great. But why I couldn't do the same for the validation message, I suppose it would give developers more flexibility and convience. I know what I could use overriding of Extensions methods just like this:

public static MvcHtmlString ValidationMessage(this HtmlHelper Html, string Model)
   {
     return System.Web.Mvc.Html.ValidationExtensions.ValidationMessage(Html, Model);
   }

But as long with this one I should also overri开发者_运维问答de ValidationMessageFor, also it is divert from the general implementation of html code templating for MVC.

Question: that is the best practise to solve problem of this kind?

Thanks!


When I've needed to customise my ValidationMessageFor elements, I've used css to target the rendered tag.

The only templates I'm aware of are EditorTemplates and DisplayTemplates - which require "EditorFor" and "DisplayFor" respectively. ValidationMessageFor is hard coded.

I did find some posts here and here, which should help you write your own method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜