[英]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.