asp.net mvc区域内样式表中的相对路径 [英] relative path in stylesheets within asp.net mvc areas

查看:80
本文介绍了asp.net mvc区域内样式表中的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有当前结构的项目

I have a project with the current structure

My Project
  /Content
  /Controller
  /View
  /Model
  /Areas
     /Area1
        /View
        /Controller
        /Model
     /Area2
        /View
        /Controller
        /Model

所有区域视图都使用根共享_Layout视图,该视图引用根目录目录下的css文件.内容文件夹下的css文件正在引用具有相同目录的图像或其他内容,如下所示:

All of the area views are using a root shared _Layout view which is referencing a css file under the root content directory. The css file under the content folder is referencing images or other content with the same directory like below:

.box-shadow
{
    -webkit-box-shadow: 0px 5px 80px #505050;
    -moz-box-shadow: 0px 5px 80px #505050;
    box-shadow: 0px 5px 80px #505050;
    behavior: url('../Content/PIE.htc');
}

当我访问"http://MyProject/controller/action"时,所有这些工作正常,但是当我进入"http://root/area/controller/action"区域时,我的css文件无法找到路径"../Content/PIE.htc".

All of this works fine when i access 'http://MyProject/controller/action', but when i go into an area 'http://root/area/controller/action' my css file is not able to find the path '../Content/PIE.htc'.

我不知道如何解决此问题,所以我想知道是否有人知道解决此问题的方法.

I don't know how to go about fixing this so i was wondering if anyone knew of a way to fix this.

谢谢!

推荐答案

如果所有区域中的所有视图都使用根共享的_Layout(〜/Views/Shared/_Layout.cshtml),请确保_Layout.cshtml调用css文件,如下所示:

If all the views in all the areas are using root shared _Layout (~/Views/Shared/_Layout.cshtml), make sure that _Layout.cshtml calls css file like the following code:

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />

我用MVC 3对其进行了测试,并且可以正常工作.

I tested it with MVC 3 and it works.

这篇关于asp.net mvc区域内样式表中的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆