Usercontrols in MVC

Jul 17, 2008 at 5:37 PM
Hi

Another question: I'd like to be able to pull content items into a page using the composition method. The idea is to define zones on the page itself so that cms editors can add as many pieces of content as they desire into the page. I think that the best way to do this would be to use the MVC user controls.

The problem that I've run into is that each user control has it's own strongly typed viewdata, which is different from that of the parent page. when I loop through the collection of user controls in the page, I cannot access their viewdata, which I intend to use in conjunction with Html.RenderUserControl to render the control. User controls with no dynamic data load fine, but obviously this is pretty useless!

Does anyone know how I could solve this issue?

I can provide some code if this question is a bit vague - it's late in the day!
Coordinator
Jul 17, 2008 at 6:56 PM
The way I picture this is something like this:

<% foreach(ContentItem part in ViewData.Model.GetChildren("ZoneName")) { %>
  <%= Html.RenderUserControl(part.TemplateUrl, part) %>
<% }%>

But... Does the MVC pattern provide any additional benefit in this scenario? I mean, there's not much for the controller to do. I suppose you could have it figure out which parts to show. Couldn't you just use the DroppableZone and the DragDropControlPanel web controls and get drag and drop?

I haven't looked at this in depth nor tried if any of the proposed solutions. I'd happily be educated from your experiences.
Jul 18, 2008 at 1:51 PM
Thanks very much - it's working great now.

I don't think that the MVC pattern really offers extra benefits in this scenario, although I am keen to keep things consistent throughout the project and so would rather use it here. If I run into issues further down the line I shall be sure to report them though, just in case it saves others any headaches.

Thanks again,

Graham