[英]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.