Q:

ASP.NET MVC Model Data Binding

Is there a way to bind data to a class member? Here is an example
public class A
{
   public int ID {get; set;}
   public string Description {get; set;}
}

public class B
{
   public int ID {get; set;}
   public string Description {get; set;}
   public A a {get; set;}
}

[HttpPost]
public ActionResult Create(Class B)
{

}

Now I want create an class B object in a View page, the posted data comes from this page is below:
     ID = 1
     Description = "Description B"
     A = 1
I want to all the above data is able to automatically filled into an instance B and the MVC is able to fill 
the ID of class B, the description of class B, but is not able to fill data into the class A which is a member of Class B.
Actually All I want is when the posted data A = 1, then the MVC can be create an new instance of class A for class B, and set the ID values of class A to 1.
I know there might be put some attributes on class A, and it will tell MVC do some mappings based on the attributes.

A:

How can a value of 1 be bound to a complex property of type A? It's got nothing to do with some attributes on class A! You need to construct your html correctly so it can be bound
Controller
public ActionResult Create()
{
  B model = new B();
  return View(model)
}

[HttpPost]
public ActionResult Create(B model)
{

}

View
@model B
@using(Html.BeginForm())
{
  @Html.TextBoxFor(m => m.ID)
  @Html.TextBoxFor(m => m.Description)
  @Html.TextBoxFor(m => m.a.ID) 
  @Html.TextBoxFor(m => m.a.Description)
  <input type="submit" value="Save" />
}

