简体   繁体   English

验证消息颜色 ASP.NET MVC 4

[英]Validation message color ASP.NET MVC 4

I am using ASP.NET MVC 4 Razor.我正在使用 ASP.NET MVC 4 Razor。

I want to change the validation color message to Red.我想将验证颜色消息更改为红色。 It's not working even if I change the CSS file.即使我更改了 CSS 文件,它也不起作用。

My CSS file:我的 CSS 文件:

.field-validation-error {
  color: #E80C4D;
  font-weight: bold;
}

.field-validation-valid {
  display: none;
}

input.input-validation-error {
  border: 1px solid #E80C4D;
}

input[type="checkbox"].input-validation-error {
  border: 0 none;
}

.validation-summary-errors {
  color: #E80C4D;
  font-weight: bold;
  font-size: 1.1em;
}

.validation-summary-valid {
  display: none;
}

A part of my view:我的一部分观点:

<td>@Html.LabelFor(model => model.nom_candidat)</td>

<td>
    @Html.TextBoxFor(model => model.nom_candidat)
    @Html.ValidationMessageFor(Model => Model.nom_candidat)
</td>

You can pass a style attribute as the third argument to the ValidationMessageFor method in a razor view as such:您可以将样式属性作为第三个参数传递给剃刀视图中的 ValidationMessageFor 方法,如下所示:

@Html.ValidationMessageFor(m=>m.StudentName, "", new { @style="color:red" })

For a more generic solution , you can also run your application trigger the validation message.对于更通用的解决方案,您还可以运行您的应用程序触发验证消息。 In Chrome, right click the validation message and inspect the element, go to the debugger window and trace the class associated with the validation error message.在 Chrome 中,右键单击验证消息并检查元素,转到调试器窗口并跟踪与验证错误消息关联的类。

Go to file site.css and overwrite the default validation-error message class as shown below:转到文件site.css并覆盖默认的验证错误消息类,如下所示:

span.field-validation-error{
     color: red;
}

您可以使用这段代码来更改验证颜色:

@Html.ValidationMessageFor(m=>m.FirstName, "", new{@class="text-danger"}) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM