How to use @RenderPage to include CSS content inli

2019-05-08 21:48发布

问题:

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

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.

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

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.

回答1:

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

what I needed is this:

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