简体   繁体   English

更改 ModelState.AddModelError 消息的字体颜色

[英]Changing the FONT color of the ModelState.AddModelError message

Consider this bit of .NET Core goodness.考虑一下 .NET Core 的这一点。 If you have an error with the state of the model you can just:如果模型状态有误,您可以:

ModelState.AddModelError(string.Empty,
"Invalid login attempt.");

The only issue is the formatting of the message is not so nice and the red color doesn't work for my UI.唯一的问题是消息的格式不太好,红色不适用于我的 UI。

Is there a way to simply change the message color?有没有办法简单地更改消息颜色?

I have tried我试过了

ModelState.AddModelError(string.Empty,
"<style='color:black'><strong>Invalid login attempt.<strong></style>");

but that did not have the desired result.但这并没有达到预期的结果。

Take a look at the examples here .看看这里的例子

If you use the Html.ValidationMessageFor tag helper in your view, you will get HTML like the following example (from the above link):如果您在视图中使用Html.ValidationMessageFor标签助手,您将获得类似于以下示例的 HTML(来自上面的链接):

<span class="field-validation-error" data-valmsg-for="Email"
            data-valmsg-replace="true">
   The Email Address field is required.
</span>

Then all you need to do is add styles for the class "field-validation-error" in your CSS file.然后您需要做的就是在 CSS 文件中为“field-validation-error”类添加样式。

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

相关问题 未在PartialView中显示Modelstate.addmodelerror - Modelstate.addmodelerror not showing in PartialView 创建一个类型化的ModelState.AddModelError() - Creating a typed ModelState.AddModelError() ModelState.AddModelError 这里我给出的错误消息没有显示 - ModelState.AddModelError here the error message I gave its not showing 未绑定模型项时如何添加 ModelState.AddModelError 消息 - How to add ModelState.AddModelError message when model item is not binded Asp.Net Core Razore Pages 中的“ModelState.AddModelError”显示不正确的错误消息 - Incorrect error message is displayed by "ModelState.AddModelError" in Asp.Net Core Razore Pages ModelState.AddModelError 在 asp.net.core RAZOR 页面中不显示任何消息 - ModelState.AddModelError doesn't show any message in asp.net.core RAZOR pages 添加ModelState.AddModelError而无需重新加载页面(mvc4) - Add ModelState.AddModelError without reload the page (mvc4) ASP.NET MVC 2 RC在表单级别上的ModelState.AddModelError - ModelState.AddModelError on form level with ASP.NET MVC 2 RC 当MVC4中的模型为空时如何显示ModelState.AddModelError - How to show ModelState.AddModelError when the Model is Empty in MVC4 通过javascript提交表单后将ModelState.AddModelError添加到视图中 - Add ModelState.AddModelError to the view after submitting form through javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM