0

我有一个表格,我在这个表格中保存了三个实体。

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 达到学生模型。但它给出了错误。

 NewAccountWrapperModel' does not contain a definition for 'Student' and no extension   method 'Student'

像这样。在 Person 模型中,有 Name 字段。我控制了它。

4

1 回答 1

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; }
于 2013-08-05T22:01:48.423 回答