Michael DeLorenzo
Michael DeLorenzo

Reputation: 1140

RE: Using themes with ASP.Net MVC

I have an ASP.NET MVC (Beta 1) website that I'm using themes with. When I start my site (I'm still running using the ASP.Net Development Web Server) the default page gives me this error:

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 

Do I need to change something with my routes? Or do I need to do something else to my site?

Upvotes: 1

Views: 5009

Answers (4)

Michael Ryan
Michael Ryan

Reputation:

This was my solution http://frugalcoder.us/post/2008/11/ASPNet-MVC-Theming.aspx just posted about this today...

Upvotes: 1

Richard Szalay
Richard Szalay

Reputation: 84724

The error is telling you that your ASP.NET page (or master page) needs to have a <head runat="server"> tag. Without it, you cannot use themes.

Since server side header tags shouldn't have a dependency on viewstate (as they are not contained in forms), it might still work.

Having said that, themes don't necessarily sit well in the MVC paradigm so you should consider whether you really need them.

Upvotes: 2

Michael DeLorenzo
Michael DeLorenzo

Reputation: 1140

I like your idea Jason, thanks for the tip. That would actually be very easy for me to implement. :)

Just as an fyi for anyone trying to do what I am/was doing with the Themes, I simply added the header element to the default.aspx page, and all was taken care of - just what Richard suggested.

Upvotes: 0

Jason Whitehorn
Jason Whitehorn

Reputation: 13685

A cleaner idea is to just have a "theme" consisting of CSS. In your master page (or individual views) link to the appropriate CSS files.

For example, I keep my "themes" in a theme directory under the Content directory of the site root. Each theme lives in its own folder, and has a main.css. The main.css is responsible for referencing all the other required CSS. So the master page in my example just links to the one main.css. You can even set the ViewData["theme"] variable (if you wanted) to the theme name, so the Master page could simply use that as a place holder for the correct theme directory.

Upvotes: 3

Related Questions