I have a question on representing complex views on a View. Since my code is already complex, I have come up with a simple model for purposes of seeking an answer.
Consider this as my model class and the complex type
public class Person
{
public string FirstName { get; set; }
public string Surname { get; set; }
public string Phone { get; set; }
public List<Address> Address {get; set;}
}
[ComplexType]
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
}
If for instance I want to use html helpers for displaying a TextBox for FirstName then this would work
@Html.TextBoxFor(model => model.FirstName, new { @class = "Name" })
I have a problem now rendering say a Textbox for Address' Street property. I don't want to hard code it into the view and I would really prefer using a Lambda expression to get a text box for say street, city and state. Though this syntax is wrong, here is what am trying to accomplish
@Html.TextBoxFor(model => model.Address.Street, new { @class = "Name" })
Or something legal in C# that would abstract me from typing names for input controls right into helper methods. This is because while using Model Binding for my project, I don't want trips back to my Views to hard code an inputs name once my model changes.
UPDATE Address is a List type. I have updated the code to reflect the fact that Address is a List of type Address in my code.