为什么主题不能很好地适应 MVC 范式?

发布于 2024-08-07 02:45:19 字数 771 浏览 5 评论 0原文

我正在研究新的 ASP.NET MVC 区域并将其与主题混合。在没有区域的 MVC 中,我曾经通过添加到 Views 文件夹中的 Web.Config 来应用主题

<pages theme="ThemeName" ... > ... </pages>

,并且效果非常好。现在我有一个 Areas 文件夹,每个文件夹都有自己的 Web.Config,我的主题仅适用于非区域控制器中的控制器(这很有意义)。我想更改单个 Web.Config 中的默认主题,但包含所有文件夹的唯一主题位于根目录中,这会在您点击 Default.aspx 页面时导致错误。

编辑:在 ASP.NET MVC 2 中,事实证明他们删除了网站根目录中的 Default.aspx 页面,这样您现在就可以在根 Web.Config 中指定主题,而无需使用由于文件夹结构的原因,问题也适用于区域。

除此之外,我不明白为什么“主题不一定很好在 MVC 范式中”。 MVC 中的一个主要概念是通过抽象层分离关注点。我不明白为什么视图不能抽象为两个单独的实体,即用户界面中给定点显示的数据以及数据样式的主题。

我有两个问题:

  1. 是否可以在单个 Web.Config 中为此类项目指定主题? [已在编辑中解决。]
  2. 为什么主题不能很好地适应 MVC 范例?

I am working with the new ASP.NET MVC areas and mixing it with themes. In MVC without areas I used to apply themes by adding

<pages theme="ThemeName" ... > ... </pages>

to the Web.Config in the Views folder, and it worked perfectly. Now that I have an Areas folder, each with its own Web.Config, my theme is only applying to controllers in the non areas controllers (which makes perfect sense). I would like to change the default theme in a single Web.Config, but the only one which encompasses all my folders is in the root, which causes an error when you hit the Default.aspx page.

EDIT: In ASP.NET MVC 2, it turns out they removed the Default.aspx page in the root of the website, making it so you can now specify the theme in the root Web.Config without a problem and it applies to areas as well due to the folder structure.

Aside from this, I don't understand how "themes don't necessarily sit well in the MVC paradigm" either. A major concept in MVC is separation of concerns through layers of abstraction. I don't see any reason why the view can't be abstracted to two separate entities, the data displayed at given point in a user interface and the theme that data is styled to.

I have two questions:

  1. Is it possible to specify the theme in a single Web.Config for this type of project? [Solved in edit.]
  2. Why don't themes sit well in the MVC paradigm?

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

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

发布评论

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

评论(3

跨年 2024-08-14 02:45:19

Asp.Net 主题与 Asp.Net 紧密集成(具有许多特定的挂钩点:创建 Arnis 提到的配置文件;有一个 标记; 等..),要使其与 MVC 一起工作,需要您在主要 MVC 组件之间创建连接,这本质上违背了 MVC 的目的(关注点分离)。

Asp.Net Themes are so tightly integrated into Asp.Net (with many particular hook points: creating profiles mentioned by Arnis; having a <head runat="server"> tag; etc..) that to get it working with MVC requires you to create wiring between the major MVC components which intrinsically goes against MVC's purpose (separation of concerns).

蔚蓝源自深海 2024-08-14 02:45:19

简单的。

主题在 MVC 范式中不太合适,因为管理主题属于表示层,而 UI 相关的内容应该由它专门处理。

当使用主题时 - 您正在告诉您将如何在控制器甚至模型中显示某些内容(即 - 您为每个用户或某些内容创建配置文件),这与提到的范例相冲突。

但不要忘记 MVC 不是宗教。

Simple.

Themes does not sit well in MVC paradigm because managing themes belongs to presentation layer and UI related stuff should be handled by it exclusively.

When working with themes - you are telling how you are going to show something in Controllers or even Model (i.e. - you create a profile for every user or something) and that's a conflict with mentioned paradigm.

But don't forget that MVC ain't religion.

无妨# 2024-08-14 02:45:19

把WFVE赶出去。安装 Spark。阅读有关主题化的文档。实施。享受。

Throw WFVE out. Install Spark. Read docs about theming. Implement. Enjoy.

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