我有两个课程,例如:
public class Person
{
[Required]
public string Name { get; set; }
public Address HomeAddress { get; set; }
}
public class Address
{
[Required]
public string StreetName { get; set; }
public int Number { get; set; }
}
当我发布表单时,只有在“Person.Name”属性中出现消息“Name字段是必需的。”
为什么它不出现在“HomeAddress.StreetName”属性中?
@model SqlExpress.Models.Person
<form asp-action="Create">
<input asp-for="Name" />
<input asp-for="HomeAddress.StreetName" />
...
答案 0 :(得分:0)
它与Razor视图引擎配合得很好。 您是否忘记添加类似于下面提到的验证消息字段?
@Html.ValidationMessageFor(model => model.HomeAddress.StreetName)