[英]How to render image path correctly in Razor when using bundle configuration
BundleConfig.cs snippet BundleConfig.cs代码段
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/bundles/css").Include(
"~/content/themes/base/jquery.ui.core.css",
"~/content/themes/base/jquery.ui.theme.css"
}
_Layout.cshtml snippet _Layout.cshtml代码段
@Styles.Render("~/bundles/css")
jquery.ui.theme.css snippet jquery.ui.theme.css代码段
url(images/ui-bg_flat_75_ffffff_40x100.png)
Firebug reports that the image (my_app_path) / bundles / images / ui-bg_flat_75_ffffff_40x100.png` 404 not found. Firebug报告未找到图片(my_app_path) /包/图片/ ui-bg_flat_75_ffffff_40x100.png` 404。
How can I tell Razor that the correct path is actually (my_app_path) / content / themes / base / images / ui-bg_flat_75_ffffff_40x100.png`? 我如何才能告诉Razor正确的路径实际上是(my_app_path) /内容/主题/基础/图片/ ui-bg_flat_75_ffffff_40x100.png`?
EDIT: ELMAH spits this error for the same issue: 编辑: ELMAH为同一问题吐出此错误:
System.Web.HttpException: The controller for path ' / bundles / images / ui-bg_flat_75_ffffff_40x100.png' was not found or does not implement IController.
System.Web.HttpException:找不到路径' / bundles / images / ui-bg_flat_75_ffffff_40x100.png'的控制器或未实现IController。
This is happening because your CSS files aren't being rewritten to transform their relative paths. 发生这种情况是因为您的CSS文件没有被重写以转换它们的相对路径。 You can make this happen by changing to the following:
您可以通过更改以下内容来实现此目的:
bundles.Add(new StyleBundle("~/bundles/css").Include(
"~/content/themes/base/jquery.ui.core.css",
"~/content/themes/base/jquery.ui.theme.css",
new CssRewriteUrlTransform()));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.