I have an "Embedded Resource" view. In this view I am using the following model
public class TestModel
{
public TestModel()
{
CustomModel1 = new CustomModel1 ();
CustomModel2 = new CustomModel2();
}
public CustomModel1 CustomModel1 { get; set; }
public CustomModel2 CustomModel2{ get; set; }
}
In this view I have a form and inside it I am using @Html.EditorFor
instead of @Html.Partial
, because when I use @Html.Partial
the CustomModel1 passed to the action (when the form is submitted) is empty.
@Html.EditorFor(m => m.CustomModel1, Constants.CustomEmbeddedView1)
However when I use @Html.EditorFor
and pass as a template a "Content" view
@Html.EditorFor(m => m.CustomModel1, "~/Views/Common/_CustomPartialView.cshtml")
I get the following error:
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.Int32'.
If I set the "Content" view to be an "Embedded Resource" everything works fine.
Is there any way to resolve this problem? Perhaps there is another solution to the model binding problem instead of using @Html.EditorFor
.