Placing MVC Content folder into Area

Go To StackoverFlow.com

5

First of all, I do understand, that MVC 3 default template's Content folder is not a mandatory css/img/etc. store folder.

I still like the concept of Content folder to be a "reference-able" storage location for images and style sheets and other possible stuff (I also place entire jQuery custom controls into Content's sub folders with .js files in them).

I haven't used MVC Areas thus far in my projects, since I didn't have a complex enough one's. Now it's time.

And I am thinking about placing a separate Content folder in each Area. Will it work? Is there something "bad" that can turn out of it? Like me not being able to reference resources in it via ../Content/MyControl? Or is MVC Area just like a root of the project, but a separate one?

2012-04-05 17:20
by Maxim V. Pavlov


6

The area is almost just like a separate project (but not really). You can either use

Url.Content("~/Areas/AreaName/Content/FileInfo");

or

<link type="text/css" src="RootOfSiteInfo/Areas/AreaName/Content/FileInfo"/>

There should not be any issues not being able to reach the static content, though personally I leave everything in the root content folder (single point of storage) since many times CSS and the likes are shared in our projects across areas.

2012-04-05 18:04
by Tommy
the iis tells 40 - AgentFire 2012-07-31 08:29
I was only be able to make it work by adding "Areas" to the url. If someone knows how to avoid this I would be appreciated - Diogo Gomes 2012-09-12 13:10
If the physical path from your site root is Areas/AreaName/Content/file.ext, then yes, you would need to include Areas in the path - Tommy 2012-09-12 15:37
Ads