将通用布局应用于 ASP.NET MVC 中的 ascx 控件

发布于 2024-08-18 05:57:39 字数 252 浏览 0 评论 0原文

在 MVC 中实现部分 ascx 视图的视觉继承的最佳方法是什么?

我有主 Site.Master 文件,它提供页眉、页脚、侧边栏和主要内容区域。然后我有一个 Info.Master,它使用 Site.Master 作为它的母版页,并为几乎相同的页面提供通用布局。然后站点上所有这些类似的“信息”页面都将 Info.Master 设置为其母版页。

现在我想对侧栏上出现的 ascx 部分视图执行相同的操作,因为我有一些控件“看起来”都相同,包括页眉、页脚等?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扮仙女 2024-08-25 05:57:39

您可以使用普通的 ASPX 视图作为局部视图,并使用常见的局部布局元素为它们创建另一个母版页。查看这篇文章<来自 Jeffrey Palermo 的 /a> 了解有关此技术的更多信息。

另一种选择是将常见的部分布局元素放在一个主母版页中,并利用视图位置。例如,如果您有一个名为“Sidebar”的部分,其内容仅针对每个控制器进行更改,则您可以在 Views/Shared 目录中创建通用部分,并在每个 Views/目录中创建更具体的部分。目录,部分内容将被覆盖。

<div id="sidebarheader">...</div>
    <% Html.RenderPartial("Sidebar"); %>
<div id="sidebarfooter">...</div>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文