I need to update a company class with an IList of addresses. These are my Data Models.
// Entity class Company — managed by Nhibernate
public class Company
{
public virtual IList<Address> _addresses { get; set; }
public Company()
{
_addresses = new List<Address>();
}
}
// Entity class Address — managed by Nhibernate
public class Address
{
public virtual string line1 { get; set; }
public virtual string line1 { get; set; }
}
I am packing the data from the Entity class to the Viewmodel in the controller's GET action, and I am unpacking the data from the Viewmodel back to the Entity class in the controller's POST action.
Here are my View Models.
// Class CompanyRequest
public class CompanyRequest
{
public IList<AddressRequest> AddressRequests;
}
//Class AddressRequests
public class AddressRequest
{
public string line1 { get; set; }
public string line1 { get; set; }
}
I am using a partial view to display each address box. For each AddressRequest in AddressRequests I pass the object to a partial view with the prefix set correctly.
for(var i = 0 ; i < AddressRequests.Count() ; i++)
{
ViewData["Prefeix"] = String.Format("AddressRequests[{0}]", i);
Html.RenderPartial("_addressPartial", AddressRequests[i]);
}
I need to be able to add an "Add New Address" button so that the user can add a new address to this list. This has to be done WITHOUT refreshing the page. When the user clicks that button, another address-box (same partial, I'm guessing) appears. Then the user edits the box and presses a "Save" button. This Save button is supposed to save the whole Company data, not just the Address.
Is there a way to do this? Any help is greatly appreciated!