2013-08-05 70 views
0

我有一個表單,我在這個表單中保存了三個實體。在asp.net中保存多個模型mvc

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' 

這樣子。在人物模型中,有名稱字段。我控制它。

回答

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; } 
+0

感謝這麼淤泥。這是我的粗心。我不知道這一點。再次感謝。 – miyamotomusashi