如何使用@RenderPage包含内联CSS内容-MVC Razor [英] How to use @RenderPage to include CSS content inline - MVC Razor

查看:203
本文介绍了如何使用@RenderPage包含内联CSS内容-MVC Razor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在将项目中的页面导出到Excel中,这将不允许链接外部内容,例如外部CSS。

I am currently exporting a page from my project into Excel which will not allow the linking of external content e.g. external CSS.

我想要实现的是一种在CSS 视图中包含CSS文件的简单方法,但是要拥有它直接从CSS文件中调用,而CSS文件会被Visual Studio自动缩小。

What I am trying to achieve is a simple way to include a CSS file in my view but to have it called directly from a CSS file which will have automatically been minified by Visual Studio.

因此,在我看来,我已经尝试过:

So, in my view I have tried this:

<style type="text/css">
   @RenderPage("~/CSS/_ExportStyles.min.css")
</style> 

但这样做会返回以下错误:

but doing this returns the following error:

'/'应用程序中的服务器错误。

Server Error in '/' Application.

由于其扩展名为 .css
,因此无法呈现以下文件可能不受支持:〜/ CSS / _ExportStyles.min.css。

The following file could not be rendered because its extension ".css" might not be supported: "~/CSS/_ExportStyles.min.css".

我知道可以的是放置CSS包含在普通的 .cshtml 文件中,但包含该文件,但是我将无法使用。min 文件

What I know will work would be to place the CSS in a normal .cshtml file and include that, but I would lose the ability to ".min" the file which keeps the file size small and allows me to automatically strip out comments etc.

推荐答案

因此,事实证明 @RenderPage 不是我想要的...

So, it turns out that @RenderPage is not what I was looking for...

我需要的是这

@ Html.Raw(File.ReadAllText(Server.MapPath(〜/ CSS / _ExportStyles.min.css)))

这篇关于如何使用@RenderPage包含内联CSS内容-MVC Razor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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