This question has been asked but none could solve my problem. The problem is missing or null data from the partial view is not submittied (POST) along with the main view data.
I have a typed partial view called _Address.cshtml that I include in another view called Site.cshtml.
The typed site view binds to a view model called SiteEditModel.cs
public class SiteEditModel
{
...properties
public AddressEditModel Address {get;set;}
public SiteEditModel()
{
Address = new AddressEditModel();
}
}
The Site view has a form:
@model Insight.Pos.Web.Models.SiteEditModel
...
@using ( Html.BeginForm( "Edit", "Site", FormMethod.Post ) )
{
@Html.HiddenFor( m => m.SiteId )
...
@Html.Partial( "~/Views/Shared/Address.cshtml", this.Model.Address )
...
@Html.SaveChangesButton()
}
The partial Address view is just a bunch of @Html... calls that bind to the Address model.
@model Insight.Pos.Web.Models.AddressEditModel
@{
Layout = null;
}
<div>
@Html.HiddenFor(...)
@Html.HiddenFor(...)
@Html.HiddenFor(...)
@hmtl.LabelFor(...)
</div>
In the controller action Edit I can see the SiteEditModel is populated correctly, the Address property of that model is not. Where do I go wrong?
Thank you so much.