Here are my model.
public class InfoModel
{
public NameModel Name { get; set; }
public string Phone { get; set; }
}
public class NameModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public NameModel(string first, string last)
{
this.FirstName = first;
this.LastName = last;
}
}
Then I have a partial View just for displaying names as follows
@model MyTestApp.Models.NameModel
@Html.LabelFor( m => m.LastName)
@Html.TextBoxFor( m => m.LastName)
<br />
@Html.LabelFor( m => m.FirstName)
@Html.TextBoxFor( m => m.FirstName)
Then there is a view for ShowInfo
@model MyTestApp.Models.InfoModel
@using (@Html.BeginForm())
{
@Html.Partial("ShowName", Model.Name)
<br />
@Html.LabelFor( m => m.Phone)
@Html.TextBoxFor(m => m.Phone)
<br />
<input type="submit" value="Submit Info" />
}
Now user submit any info, following controller method is called
[HttpPost]
public ActionResult ShowInfo(InfoModel model)
{
...
}
Problem is when i inspect the value of model, phone is fine but name is null. Any ideas how to make it work?