My ASP.NET MVC viewmodel is designed as below
public class Customer
{
public int CustomerId{ get; set; }
public string CustomerName{ get; set; }
public Address CustomerAddress {get;set;}
}
public class Address
{
public int AddressId{ get; set; }
public string HouseName{ get; set; }
public string Location{get;set;}
}
How can I bind Address object properly in cshtml page so that it should be available after form Submit.
In cshtml page I want bind it the properties as below
@model CustomerManagement.Model.ViewModels.Customers.Customer
@using (Html.BeginForm())
{
@Html.EditorFor(model => model.CustomerName, new { htmlAttributes = new { @class = "form-
control readOnlySchdCode", @readonly = "readonly" } })
@Html.Hidden("AddressId", Model.Address.AddressId)
@Html.Hidden("HouseName", Model.Address.HouseName)
}
In controller form submit will look like as below
public async Task<ActionResult> AddCustomer(Customer model)
{
//How can i access Address properties eg:model.CustomerAddress.AddressId??
}
Can anyone share a sample code on how to bind the Above viewmodel properly in cshtml using razor template and how properties are properly retrieved in Action method while form submit.

