I have a complex model class like:
public class Client
{
public string Name { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string AddressLine { get; set; }
}
My View is made of several Partial's on which I pass parts of the model into them and dispose some fields for edition:
In Index.cshtml
@using (Html.BeginForm("Index"))
{
@Html.DisplayNameFor(modelItem => model.Name)
@Html.DisplayFor(modelItem => model.Name)
<div id="divAddress">
@Html.Action("_Address", model.Address)
</div>
<div>RESULT MESSAGE GOES HERE!</div>
<input type="submit" value="Submit" />
}
In _Address.cshtml
@Html.DisplayNameFor(modelItem => model.AdressLine)
@Html.EditorFor(modelItem => model.AdressLine)
On the code-behind my Actions consist of two simple ActionResults methods:
[HttpGet]
public ActionResult Index()
{
Client = new Client();
Client.Name = "António Fonseca"
return View(model);
}
[HttpPost]
public ActionResult Index(Client model)
{
return View(model);
}
public ActionResult _Address(Address model)
{
return View(model);
}
When I submit the form, I need to call a WebService with the full Client
structure and display it's resulting message.
What happens is that when hitting Index(model) -> model.Address
is null.
It's only bound back when it hits _Address(model)
method.
Is there a way to bind the full class structure in main Action using PartialViews?