将类样式传递给MVC Razor C3验证

本文关键字:MVC Razor C3 验证 样式 | 更新日期: 2023-09-27 18:12:21

使用MVC验证,我这样做来显示错误消息

@Html.ValidationMessageFor(x => x.QuestionText)

显示HTML

<span class="field-validation-error" data-valmsg-replace="true" data-valmsg-for="QuestionText">
<span class="" for="QuestionText" generated="true">Please fill in a question before Assigning it</span>
</span>

但是我也想传递style类,比如:

 @Html.ValidationMessageFor(x => x.QuestionText, new {@class="notification error"})

但这不起作用吗?

将类样式传递给MVC Razor C3验证

试试这个;

@Html.ValidationMessageFor(x => x.QuestionText, null, new {@class="notification error"})