Revisiting an old post

I wrote a post about using Variables in CSS a while back (here).

Someone asked a question about something similar so I thought I’d rewrite it for MVC3. It seems that adding the [OutputCache] to the method changes the ContentType from “text/css” to “text/html” causing the CSS to not be applied.

[OutputCache(VaryByParam = "none", Duration = 3600)]

public ActionResult Index()
{

	var cssDefs = new Css();

	cssDefs.Background = "808";
	cssDefs.Width = "500px";
	cssDefs.WrapperMargin = "0 auto";
	cssDefs.Foreground = "ff0";

	Response.Filter = new CSSCompressor(Response.Filter);

	Response.ContentType = "text/css";
	
	return View(cssDefs);
}

How would I go about keeping the ContentType and Caching the output?

I moved the ContentType to the View.

@model CSSControl3.Models.Css
@{Layout = null;
  Response.ContentType = "text/css";}