Reputation: 539
I have a form that I save three entites in this form.
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;
}
}
I prepare a model like above. In my html page, I uses it like below:
@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>
I try to achive to Student model using d.Student.Name. But it gives error.
NewAccountWrapperModel' does not contain a definition for 'Student' and no extension method 'Student'
like this. In Person model, there is Name field. I controlled it.
Upvotes: 0
Views: 203
Reputation: 3541
Change from:
Person Student = new Person();
Person Parent = new Person();
Reports Reports = new Reports();
to:
public Person Student { get; set; }
public Person Parent { get; set; }
public Reports Reports { get; set; }
Upvotes: 1