MVC3 Razor Stylesheet inside area
I am using mvc3 with razor. I have a normal website structure with an area for a sm开发者_运维百科all backend. In that area I wan't a folder with my "content" (stylesheets, js) that is only used by my backend.
WHat is the right way to reference this in my layout page of my backend?
Thx in advance :)
You need to consider the fact that an Area in MVC isn't really a physical folder-structure like it would seem in the URL (or your project). I would simply organize it something like this:
/Content/Public/Css
/Content/Public/Images
/Scripts/Public/
and
/Content/BackEnd/Css
/Content/BackEnd/Images
/Scripts/BackEnd
UPDATE To clarify what I mean that Area isn't a physical folder-structure:
If you have the Area Admin in your project, The Default RouteURL is /Admin/{controller}/{action}, not /Areas/Admin/{controller}/{action} (though you're free to setup your routes like that, of course)
This means that if you add a Content-folder under your /Areas/Admin folder, and place your CSS-file within that - Visual Studio wont interpret that correctly if you simply drag and drop the file into your markup. The HTML will be generated as:
<link href="../../Areas/Admin/Content/StyleSheet1.css" rel="stylesheet" type="text/css" />
whereas the Url to the Admin-area is simply www.mysite.com/Admin/
This causes a bit of confusion as to what is the correct url to the Stylesheet?
www.mysite.com/Admin/Content/stylesheet1.css
or
www.mysite.com/Areas/Admin/Content/stylesheet1.css
?
Just a matter of opinion, but that's mine anyway :)
精彩评论