简体   繁体   English

如何更改默认 model 错误“值''无效。”?

[英]How can I change the default model error "The value '' is invalid."?

I want to change the default error text of a DropDown field.我想更改 DropDown 字段的默认错误文本。 Unfortunately I just can't get it to work.不幸的是,我无法让它工作。

I have entered my own ErrorMessage in the controller, but it does not work.我在 controller 中输入了我自己的 ErrorMessage,但它不起作用。

[Required(ErrorMessage = "Please select a country")]
public int OfficesCountryId { get; set; }

View-part:查看部分:

                        <div class="form-group">
                            <label asp-for="OfficesCountryId" class="col-md-6 control-label">Country:</label>
                            <div class="col-md-5">
                                <select asp-for="OfficesCountryId" asp-items="Html.GetEnumSelectList<Offices.OfficesCountryNumbers>().OrderBy(n => n.Text)">
                                    <option value="">@SharedLocalizer["Bitte wählen"]</option>
                                </select>
                            </div>
                            <div class="col-md-10">
                                <span asp-validation-for="OfficesCountryId" class="text-danger"></span>
                            </div>
                        </div>

在此处输入图像描述

Thanks for a hint / solution感谢您的提示/解决方案

try this尝试这个

 <option value="0">@SharedLocalizer["Bitte wählen"]</option>

and maybe change your data validation attribute并且可能会更改您的数据验证属性

 [Range(1, 200, ErrorMessage = "Please select a country")]
public int OfficesCountryId { get; set; }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MVC .Net Core 模型验证 - 值 &#39;&#39; 无效。 错误 - MVC .Net Core Model Validation - The value '' is invalid. Error 我怎样才能克服以下错误: System.IO.IOException: &#39;目录名无效。 在我的 foreach 循环中? - How can I get past the following error: System.IO.IOException: 'The directory name is invalid. in my foreach loop? 如何在C#中更改default([CustomStruct])的值? - How can I change value of default([CustomStruct]) in C#? 如何在 Razor 中单击按钮时更改模型值? - How can i change my model value on button click in Razor? 缓存键导致错误“否定二进制补码的最小值无效”。 - Cache key causes error “Negating the minimum value of a twos complement number is invalid.” 当连接到wcf服务时,为什么会看到“HTTP错误400.请求主机名无效。” - Why do I see “HTTP Error 400. The request hostname is invalid.” when connected to a wcf service 根级别的数据无效。 第1行,位置1-为什么在加载xml文件时出现此错误? - Data at the root level is invalid. Line 1, position 1 -why do I get this error while loading an xml file? 如何使用模型中的自定义属性来更改剃刀视图模型中的输入元素名称属性值? - How can I change the input element name attribute value in a razor view model using a custom attribute in a model? 如何更改WCF的默认配置? - How can I change the default configuration for WCF? 如何更改默认控件属性? - How can I change default Control properties?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM