MVC 3覆盖验证消息的CSS [英] MVC 3 override validation message css

查看:114
本文介绍了MVC 3覆盖验证消息的CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图重写默认验证CSS类验证这是现场验证错误级

I am trying to override the default validation css class for validators which is "field-validation-error" class

所以,如果我写了下面的窗体上输入验证信息:

So, if I write a Validation message for a input on my form as below:

@Html.ValidationMessageFor(m=>m.Name)

然后MVC运行在默认情况下,如下设置类消息跨度:

Then the MVC runtime is setting the class of the message span by default as below:

<span class="field-validation-error" data-valmsg-replace="true" data-valmsg-for="Name">

我的问题是,我怎么能删除CSS类字段验证错误,并与其他类(我的版本),我将在我的应用程序只有部分地区用它替换它。

My question is, how can I remove the css class "field-validation-error" and replace it with another class (my version) which i will be using it in only some areas of my application.

推荐答案

好吧...所以我把它通过设置基地现场验证错误类中的表格点域验证错误的工作根css文件......这意味着,在生成的HTML,然后在我看来,我包括新的CSS类下文提到这个类将具有最高优先级:

Ok...so I got it working by setting the base "field-validation-error" class as "form .field-validation-error" in the root css file...which means that this class will have the highest priority when the Html is generated and then in my View I included the new css class as mentioned below:

@Html.ValidationMessageFor(m=>m.Name, new { @class ="NewCssClass"})

这将产生以下标记:

<span class="field-validation-error NewCssClass" data-valmsg-replace="true" data-valmsg-for="Name">

正如你可以看到NewCssClass将覆盖在现场验证错误类中指定的默认​​验证风格...

As you can see the NewCssClass will override the default validation style specified in the "field-validation-error" class...

干杯...

这篇关于MVC 3覆盖验证消息的CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆