如何解决网络核心中的数据注释不适用于列表
我有一个包含类的列表,在类中我有数据注释。 当我在浏览器调试器中显示列表时,我只得到列表的第一个元素,其中包含我之前定义的数据注释。 其余元素只有 maxlength 标签,但没有出现数据值 我的代码如下:
类:
public partial class Employee
{
[Required]
[StringLength(25)]
public string Title { get; set; }
}
查看模型:
public class employee_view_model
{
public List<employee> listEmployee { get; set; }
}
查看:
foreach (var item in Model.listEmployee.OrderBy(z => z.Title))
{
@await Html.PartialAsync("_Row_Employ",new Employee()
{
Title = item,})
}
结果: 第一个元素是正确的。
<input class="form-control input-sm text-uppercase valid" data-val="true" data-val-length="max 25" data-val-length-max="25" data-val-required="The Title field is required." id="employ_Title" maxlength="25" name="employ.Title" readonly="readonly" type="text" value="Example 1" aria-required="true" aria-describedby="employ_Title-error" aria-invalid="false">
其余元素如下例所示: 数据值不出现。
<input class="form-control input-sm text-uppercase " id="employ_Title" maxlength="25" name="employ.Title" readonly="readonly" type="text" value="Example 2">
为什么只将数据注解放在列表的第一个元素?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。