views:

54

answers:

2

The project I'm working on allows an end-user to modify CSS code to integrate the application as best possible. Most of the CSS values are stored in a database and need to be retrieved and parsed dynamically.

I setup a Style controller, and gave each stylesheet an action, and then passed the configuration data through to the View. I set the ContentType to "text/css" and then generated the stylesheets.

This works fine, but the problem I'm running into is this: none of the code works in the application. I include it in the head code, but it doesn't parse in the code.

An example of what I do is this:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" ContentType="text/css" %>

.element {
    background-color: <%= ViewData.Model.BackgroundColor %>;
}

I include it like so:

<link href="/style/Basic" rel="stylesheet" type="text/css" media="all" />

When I include the CSS code in a partial view and include it using the ViewModel (wrapped in style tags) in an action, then everything works fine. It is when I try to parse this as a separate file when it does not work.

Is there something I am doing incorrectly? Or is there some kind of glitch?

Thanks in advance :D

+1  A: 

Use a tool such as HTTPWatch to verify that the stylesheet is being sent down and not 404'd

James Fleming
When I access the stylesheet, it looks fine. That is what's confusing me.
Swamp56
I retract that comment. Turns out that I forgot to pass an id into the URL, which is required for every controller =\ .I feel like an idiot now xD .
Swamp56
+1  A: 

Controller

 public ActionResult Basic()
    {
        Response.ContentType = "text/css";
        var basicVM = new BasicVM()
                          {
                              BackgroundColor = "Lime",

                          };
        return View(basicVM);

    }

And the View

 <%@ Page Language="C#"   Inherits="System.Web.Mvc.ViewPage<MvcApplication3.Controllers.BasicVM>"       ContentType="text/css" %>
    body {
      background-color: <%= ViewData.Model.BackgroundColor %>;
        }

and the test page

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
     <title>Test</title>
     <link href="/Home/Basic" rel="stylesheet" type="text/css" media="all" />
 </head>
 <body>
     <div>
      Test
     </div>
 </body>
 </html>

Turns everything Green

Hurricanepkt