在asp.net mvc中保存多个模型

时间:2013-08-05 21:51:19

标签: asp.net-mvc entity-framework

我有一个表单,我以这种形式保存了三个参与者。

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字段。我控制了它。

1 个答案:

答案 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; }