RE:在ASP.Net MVC中使用主题

时间:2008-10-23 12:54:39

标签: asp.net-mvc

我有一个ASP.NET MVC(Beta 1)网站,我正在使用主题。当我启动我的站点(我仍在使用ASP.Net开发Web服务器运行)时,默认页面给出了这个错误:

Server Error in '/' Application.
Using themed css files requires a header control on the page. (e.g. <head runat="server" />).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Using themed css files requires a header control on the page. (e.g. <head runat="server" />).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: Using themed css files requires a header control on the page. (e.g. <head runat="server" />).]
   System.Web.UI.PageTheme.SetStyleSheet() +2458366
   System.Web.UI.Page.OnInit(EventArgs e) +8694828
   System.Web.UI.Control.InitRecursive(Control namingContainer) +333
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378


Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053 

我是否需要使用我的路线更改某些内容?或者我是否需要对我的网站做些其他事情?

4 个答案:

答案 0 :(得分:3)

更清晰的想法就是拥有一个由CSS组成的“主题”。在您的母版页(或单个视图)中链接到相应的CSS文件。

例如,我将“主题”保存在站点根目录的Content目录下的主题目录中。每个主题都存在于自己的文件夹中,并且有一个main.css。 main.css负责引用所有其他所需的CSS。所以我的例子中的母版页只链接到一个main.css。您甚至可以将ViewData [“theme”]变量(如果需要)设置为主题名称,因此Master页面可以简单地将其用作正确主题目录的占位符。

答案 1 :(得分:2)

错误告诉您,您的ASP.NET页面(或母版页)需要有一个&lt; head runat =“server”&gt;标签。没有它,你就不能使用主题。

由于服务器端标头标签不应该依赖于视图状态(因为它们不包含在表单中),它可能仍然有用。

话虽如此,主题并不一定适合MVC范例,所以你应该考虑是否真的需要它们。

答案 2 :(得分:1)

这是我今天刚刚发布的http://frugalcoder.us/post/2008/11/ASPNet-MVC-Theming.aspx解决方案......

答案 3 :(得分:0)

我喜欢你的想法杰森,谢谢你的提示。这对我来说实际上很容易实现。 :)

对于任何试图做我正在做/正在使用Themes做的事情的人来说,我只是将标题元素添加到default.aspx页面,所有这些都得到了处理 - 正如理查德建议的那样。