Have a single model for address like
public class AddressModel
{
Public string Street1 {get; set;}
Public string Street2 {get; set;}
Public string State {get; set;}
Public string City {get; set;}
}
Make a partial view for it in Views/Shared/EditorTemplates/AddressModel.cshtml
@model MyNamespace.Models.AddressModel
<div id="Address">
Html.TextBoxFor(m => m.Street1)
//Street2
//State
//City
</div>
Now if you have your view model
public class RegisterModel
{
Public string FirstName {get; set;}
Public string LastName {get; set;}
Public AddressModel HomeAddress {get; set;}
Public AddressModel MailAddress {get; set;}
}
Simply render partial views for each address like this
<div id="form">
@Html.TextBoxFor(m => m.FirstName);
@Html.TextBoxFor(m => m.LastName);
@Html.EditorFor(m => m.HomeAddress) // !! -> this will render AdressModel.cshtml as a partial view, and will pass HomeAdress to it
//Will provide a checkbox if Mailing Address is different.
@Html.EditorFor(m => m.MailAddress)
</div>
Optionally you can wrap the call to EditorFor to your own helper method if you need more logic (additional parameters for the view or something like that)
In HttpPost method use this
[HttpPost]
public ActionResult Register(RegisterModel model)
{
}
and the addresses will bind to properties of RegisterModel.