这是一个简短的回答。有谁知道如何使用 .net mvc 非侵入式验证禁用 javascript 上的字段验证?我有一个带有 [Require]
Datannotation 的 View 模型字段,但取决于用户的决定是否需要在 View 中,我将使用 modelState.remove("场”)
。
感谢你的帮助
最佳答案
您想根据用户的决定修改规则。当不再需要该字段时,请执行以下操作:
$('#Property').rules('remove', 'required')
您可以将其包装在 #OtherProperty
的监听器中:
$('#OtherProperty').change(function(e) {
if (someCondition) {
$('#Property').rules('remove', 'required')
} else {
$('#Property').rules('add', 'required')
}
});
关于javascript - .net mvc 5 不引人注目的禁用字段验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28992601/