繁体   English   中英

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

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

我想更改 DropDown 字段的默认错误文本。 不幸的是,我无法让它工作。

我在 controller 中输入了我自己的 ErrorMessage,但它不起作用。

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

查看部分:

                        <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>

在此处输入图像描述

感谢您的提示/解决方案

尝试这个

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

并且可能会更改您的数据验证属性

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM