我有一个表单,我以这种形式保存了三个参与者。
public class NewAccountWrapperModel
{
Person Student = new Person();
Person Parent = new Person();
Reports Reports = new Reports();
public NewAccountWrapperModel(Person student, Person parent, Reports reports)
{
this.Student = student;
this.Parent = parent;
this.Reports = reports;
}
}
我准备了上面的模型。在我的html页面中,我使用它如下:
@model RAM_Web.Models.NewAccountWrapperModel
<!DOCTYPE html>
<span class="field">
<input type="text" name="firstname" id="firstname2" class="longinput" />
@Html.TextBoxFor(d=>d.Student.Name)
</span>
我尝试使用d.Student.Name获得Student模型。 但它给出了错误。
NewAccountWrapperModel' does not contain a definition for 'Student' and no extension method 'Student'
像这样。在Person模型中,有Name字段。我控制了它。
答案 0 :(得分:1)
更改自:
Person Student = new Person();
Person Parent = new Person();
Reports Reports = new Reports();
为:
public Person Student { get; set; }
public Person Parent { get; set; }
public Reports Reports { get; set; }