gpt4 book ai didi

asp.net - MVC 6 asp-validation-summary 省略属性名称以验证隐藏输入

转载 作者:行者123 更新时间:2023-12-02 05:32:13 27 4
gpt4 key购买 nike

我在模型 EmployeeBindingModelCreate View 中具有以下标记:

<div asp-validation-summary="All" class="text-danger"></div>
<input type="hidden" asp-for="EmployeeId" />

如果我按原样保留愚蠢的脚手架 Create 操作,它会将空模型传递给 View ,尽管 Controller 是为 EmployeeBindingModel 键入的。然后在提交时,客户端验证根本不起作用,但这是另一个问题的主题。

这个问题是为什么 Controller 的模型验证只为 EmployeeId 返回以下消息,而不返回属性名称?

The value '' is invalid.

最佳答案

客户端 jQuery 验证的默认值为 ignore hidden fields.

ignore (default: ":hidden") Type: Selector. Elements to ignore when validating, simply filtering them out. jQuery's not-method is used, therefore everything that is accepted by not() can be passed as this option. Inputs of type submit and reset are always ignored, so are disabled elements

要修复它,您可以覆盖。

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$.validator.setDefaults({
ignore: ""
});
</script>
}

关于asp.net - MVC 6 asp-validation-summary 省略属性名称以验证隐藏输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42166569/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com