开发者

Applying a common layout to ascx controls in ASP.NET MVC

开发者 https://www.devze.com 2022-12-17 01:51 出处:网络
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

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?


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消