将通用布局应用于 ASP.NET MVC 中的 ascx 控件
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用普通的 ASPX 视图作为局部视图,并使用常见的局部布局元素为它们创建另一个母版页。查看这篇文章<来自 Jeffrey Palermo 的 /a> 了解有关此技术的更多信息。
另一种选择是将常见的部分布局元素放在一个主母版页中,并利用视图位置。例如,如果您有一个名为“Sidebar”的部分,其内容仅针对每个控制器进行更改,则您可以在 Views/Shared 目录中创建通用部分,并在每个 Views/目录中创建更具体的部分。目录,部分内容将被覆盖。
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.