views:

212

answers:

1

What would be the best way to implement visual inheritance for partial ascx views in MVC?

I have the main Site.Master file which provides a header, footer, sidebar and main content area. Then i have an Info.Master which uses Site.Master as it's master page and which provides a common layout for almost identical pages. Then all these similar "info" pages on the site have Info.Master set as their master page.

Now i would like to do the same for the ascx partial views that appear on the side bar, as I have a handful of controls that all "look" the same, with headers, footers etc?

A: 

You could use normal ASPX views as partials, and create another master page for them with your common partial layout elements. Check out this post from Jeffrey Palermo for more information on this technique.

Another option would be to put your common partial layout elements in one of your main master pages, and take advantage of the view locations. For example, if you had a partial called "Sidebar" with content that only changes for each controller, you could create a general partial in the Views/Shared directory, and more specific partials in each Views/<controller name> directory, and the partial will be overridden.

<div id="sidebarheader">...</div>
    <% Html.RenderPartial("Sidebar"); %>
<div id="sidebarfooter">...</div>
Ryan Rivest
Thanks, that link did the trick. I had considered using views rather than partials, but i'd thought there might have been performance degredation. There was a comment towards the bottom of that link though from some guy who had benchmarked it and found no appreciable difference, so that'll do me!
krisg