对主题使用不同的 site.master 文件
有不同的 site.master 文件主题化的常见做法。现在我有我的菜单系统和基于 asp.net-mvc 站点中不同“.master”文件的不同链接和样式。另一位开发人员认为这是一种奇怪的方法,我想从社区获得一些想法。
is having different site.master files common practices for theming. right now i have my menu system and different links and styles based on different ".master" files in an asp.net-mvc site. another developer thought that was a strange approach and i wanted to get some thoughts from the community.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
“主题化”MVC 最灵活的方式似乎是提供您自己的 ViewEngine...这并不像听起来那么复杂...本质上您告诉 ViewEngine 在指定的文件夹中查找母版页和视图..或者掉落返回到基本实现的默认“Views”文件夹..
对于我自己的 MVC 主题实现,我大量引用了 Christophe Geer 的这篇文章: ASP.NET MVC 主题视图引擎 ...但我确信还有许多其他可用来源。
The most flexible way of "themeing" MVC seems to be providing your own ViewEngine ... this is not as complex as it sounds ... essentially you tell the ViewEngine to look in specified folders for Master Pages and Views .. or to fall back to the default "Views" folder for base implementations ..
For my own implemenation of MVC themes I referred heavily on this article by Christophe Geer: ASP.NET MVC Themed View Engine ... but I am sure there are many other sources available.
我认为针对不同的网站结构(不同的 HTML、不同的 CSS,...)使用不同的母版页正是它们的目的,并且不会觉得奇怪。
I think that having different master pages for different site structures (different HTML, different CSS, ...) is exactly what they are meant for and don't find it strange.
并不是说我对主文件了解很多,但似乎对不同的样式使用不同的 CSS 文件是一个更好的主意,不是吗?
Not that I know a ton about master files, but it seems like it'd be a better idea to use different CSS files for different styles, no?
特别是对于 MVC,那么查看自定义视图引擎可能更有意义。
对于更普遍的 ASP.NET,以编程方式更改使用哪个母版页是一种明智的方法。毕竟,这就是为什么可以在运行时设置该属性的原因。我确实觉得令人恼火的是 ASP.NET 不允许您这样做,除非您从对现有文件的引用开始,所以除非有一个母版页将用于绝大多数请求(因此可以被认为是“默认”)我喜欢让它开始指向一个文本文件,该文件只是说“虚拟文本文件!将以编程方式更改”。对于其他开发人员来说,如果他们看到这一点,比看到一个对于他们所看到的输出没有意义的母版页文件来说,会减少很多困惑。
回到MVC。由于它在 ASP.NET 中通常是一种明智且相当常见的技术,因此如果它满足您的需求,那么没有理由不使用它。
With MVC specifically, then it may make more sense to look a custom view-engine.
With ASP.NET more generally, changing which master page is used programatically is a sensible approach. It is after all why that property can be set at run-time. I do find it irritating that ASP.NET doesn't let you do so unless you start with a reference to an existing file, so unless there's a master page that is going to be used for the vast majority of requests (and can hence be considered a "default") I like to have it start pointed to a text file that just says "dummy text file! will be changed programatically". It makes for a lot less confusion for another developer if they see that than if they see a master page file that doesn't make sense in terms of the output they see.
Coming back to MVC. Since it's a sensible, and quite common, technique in ASP.NET generally, if it meets your needs, then there's no reason not to use it.