asp.net-core-mvc - 无法在 MVC.NET Core 应用程序的单选按钮字段上看到必需消息
问题描述
我有一个单选按钮字段,我尝试将这个字段设为必填。但是,无论我在单击提交按钮后尝试什么,页面上都不会显示必填字段消息
这是单选按钮字段
<div class=" form-group">
<div class="bisformdynamiclabel"></div>
<br />
@Html.RadioButtonFor(model => model.BIS232Request.JSONData.OwnershipActivity.Ownership, "Yes", new { id = "OwnershipAnswer_true", onclick = "displayOwnershipFieldsRow(true)" })
<label for="OwnershipAnswer_true">Yes</label>
@Html.RadioButtonFor(model => model.BIS232Request.JSONData.OwnershipActivity.Ownership, "No", new { id = "OwnershipAnswer_false", onclick = "displayOwnershipFieldsRow(false)" })
<label for="OwnershipAnswer_false">No</label>
</div>
这是模型中的代码
[Required(ErrorMessage = "Please select Yes or No for the Ownership")]
public string Ownership { get; set; }
其他字段经过验证,没有任何问题。有人可以告诉我我做错了什么吗?
解决方案
您没有任何实际显示消息的东西。具体来说,您需要以下内容:
@Html.ValidationMessageFor(m => m.BIS232Request.JSONData.OwnershipActivity.Ownership)
或者使用标签助手:
<span asp-validation-for="BIS232Request.JSONData.OwnershipActivity.Ownership"></span>
推荐阅读
- c# - JWT 不会通过 Blazor 存储在 ASP.NET Core 中
- android - Android EditText 错误消息弹出文本未显示
- php - php7 和 jQuery 中的状态栏
- c# - 当应用程序的多个实例同时使用 StreamWriter 访问同一个文件时会发生什么?
- html - 将多个div放在div的底部
- craftcms - 我没有在 Craft CMS 中的字段上设置字符限制,但由于内容太长而无法保存条目?
- c# - 使用 C# 和 Microsoft Graph SDK 从日历获取事件
- turtle-graphics - 小型基本海龟 MoveTo 错误“值对于小数而言太大或太小。”
- python - Pandas:在表格摘要中考虑输入差异和特定列值
- node.js - 节点从Debian服务器发送邮件到用户的电子邮件