Possible Duplicate:
Complex models and partial views - model binding issue in MVC3
Can you pass data from a View to a Controller when the properties are sitting within a class that is within the Model used in that View?
The problem is that when the Submit happens, it seems that properties of my Model that belong to a class within that Model do not get populated. Properties that are not in classes DO get populated. Just think there is a instantiation problem here but not seeing the path forward.
Here is the Model setup:
namespace AppName.Models
{
public class SuperModel
{
public SuperModel() {
SubModA = new SubModelA();
}
public string myItem1 { get; set; }
public SubModelA SubModA { get; set; }
}
public class SubModelA
{
public string mySubAItem1 { get; set; }
}
}
Here is the View:
@model AppName.Models.SuperModel
@{
ViewBag.Title = "My Page Title";
}
<h2>My Page Title:</h2>
@using (Html.BeginForm("NextController", "NextControllerFolder", new { SuperModel = Model }, FormMethod.Post))
{
@{
Model.myItem1 = DateTime.Now.ToShortDateString();
Model.SubModA.mySubAItem1 = DateTime.Now.ToShortDateString();
}
@Html.HiddenFor(m => m.myItem1)
@Html.HiddenFor(m => m.SubModA.mySubAItem1)
<p>
<button name="submit" value="Submit"><b>Continue</b></button>
</p>
}
Here is the Controller:
[HttpPost]
public ActionResult NextController(string button, SuperModel model, string returnUrl)
{
// PROBLEM IS HERE>>>
///model.myItem1 has a value equal to the current date
// model.SubModA.mySubAItem1 is null
return(model);
}
Hope this question made sense. Hope the answer is just around the corner! Thanks!