I have the following types and classes:
namespace MVC.Models
public class Page
{
public EditableContent Content {get; set; }
}
public class EditableContent
{
public TemplateSection SidebarLeft {get; set; }
public TemplateSection SidebarRight {get; set; }
}
I want to edit the Page
instance in my Edit.aspx
View. Because EditableContent
is also attached to other models, I have a PartialView
called ContentEditor.ascx
that is strongly typed and takes an instance of EditableContent
and renders it.
The rendering part all works fine, but when I post - everything inside my ContentEditor
is not binded - which means that Page.Content
is null
.
On the PartialView, I use strongly typed Html Helpers to do this:
<%= Html.HiddenFor(m => m.TemplateId) %>
But because the input elements on the form that are rendered by ContentEditor.ascx
does not get the Content
prefix to its id
attribute - the values are not binded to Page
.
I tried using loosely typed helpers to overcome this:
<%= Html.Hidden("Content.TemplateId", Model.TemplateId) %>
And when I'm dealing with a property that is a List<T>
of something it gets very ugly. I then have to render collection indexes manually.
Should I put both Page and EditableContent as parameters to the controller action?:
public ActionResult Edit(Page page, EditableContent content) { ... }
What am I missing?