What am I doing wrong?
You are using partial ones. Particles do not respect the navigation context. Therefore, when you look at your generated HTML source, you will see the following:
<input type="text" name="SomeProperty" value="some value" />
instead of the correct one expected with a default binder:
<input type="text" name="Step1.SomeProperty" value="some value" />
Therefore, when you submit this form, you are not properly attached to the Step1
property. The same remark for other complex properties.
One possibility is to use editor templates instead of partial ones, because they preserve the navigation context and generate their own names for your input fields.
So, instead of:
Html.RenderPartial("Step1", Model.Step1);
using:
@Html.EditorFor(x => x.Step1, "Step1")
and then move the partial ~/Views/SomeController/Step1.cshtml
to ~/Views/SomeController/EditorTemlpates/Step1.cshtml
.
If you do not want to use editor templates, but save them with partial ones, you can change the temlpate prefix inside the partial one. So, for example, inside Step1.cshtml
partial, you can put the following at the top:
@{ ViewData.TemplateInfo.HtmlFieldPrefix = "Step1"; }
Now that you are checking your generated HTML source code, the names of your own sources should be selected for the input fields. Personally, I would recommend that you use the editor template approach to avoid hard coding of the prefix and make it partially less reusable compared to editor templates.