我的应用程序下面有以下appsettings值。出于某种原因, @ Html.ValidationMessageFor 不会在服务器端显示错误消息。当我将密钥 ClientValidationEnabled 值更改为 false 时,它正常工作。我正在使用Fluent为我们下面的模型属性进行自定义验证
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
@Html.TextBoxFor(model => model.AccountSetupView.SecurityAnswer, new { @class = "customText mandatory", @title = @Html.Translate("Answer", ResourceAreas.Onboarding.AccountSetupSecurityAnswerLabel), placeholder = @Html.Translate("Answer", ResourceAreas.Onboarding.AccountSetupTextBoxSecurityAnswerPlaceholderValue), maxlength = "40" })
@Html.ValidationMessageFor(m => m.AccountSetupView.SecurityAnswer)
流利规则
RuleFor(x => x.SecurityAnswer).ValidEmail().
WithLocalizedMessage(ResourceAreas.Messages.Message_Onboarding_100007_numbersonly);