Using MVC + Spark how to get to Content files (css, js, etc)

Dec 11, 2010 at 4:47 AM

I am using the Spark view and I have my folder setup like this;

Content
-> css
-> -> screen.css
-> scripts
-> -> jquery.1.4.4.min.js
Home
-> Views
-> -> index.spark
Shared
-> Application.spark

I am trying to get to include the screen.css in the Application.spark page I have tried all sort of "../../" and "~/" and etc like this; 

    <link rel="stylesheet" href="Content/css/screen.css" type="text/css" />	

Seems everything I try is failing, I only have the minimum setup in the program file to setup the MVC server;
	    //..snip
            // create a MVC web server.
            var server = new MvcServer();
            server.ViewEngines.Add(new SparkEngine());
            server.Add(HttpListener.Create(IPAddress.Any, 8080));
            server.Add(new SimpleRouter("/", "/home/"));

            // Load controllers and embedded views.
            BootStrapper bootStrapper = new BootStrapper(server);
            bootStrapper.LoadEmbeddedViews(thisAssembly);
            bootStrapper.LoadControllers(thisAssembly);
//..snip
I can get the page to render just fine but seems I am not able to get to the Content files.
Any advise?
Thanks,
Steven 

Dec 11, 2010 at 6:02 PM

Got it working by trolling around the source. I modified my MVC setup to be like this;

            // create a MVC web server.
            var server = new MvcServer();
            server.ViewEngines.Add(new SparkEngine());
            server.Add(HttpListener.Create(IPAddress.Any, 8080));
            server.Add(new SimpleRouter("/", "/home/"));

            var module = new FileModule();
            module.Resources.Add(new FileResources("/Content", Environment.CurrentDirectory + "\\..\\..\\Content\\"));
            server.Add(module);

            // Load controllers and embedded views.
            BootStrapper bootStrapper = new BootStrapper(server);
            bootStrapper.LoadEmbeddedViews(thisAssembly);
            bootStrapper.LoadControllers(thisAssembly);

As the "Content" folder is up two directories from the "bin/Debug" at runtime thats why you need to put the extra two up\up statments in the dir path. After doing this I was able to serve css and javascript. 

Woot!

Coordinator
Dec 29, 2010 at 4:03 PM

You can also mark all resources to be copied to the output folder.

Right click on a resource, click on "Properties". Change "Copy to output directory" to something else than "Never"