How to use @RenderPage to include CSS content inline - MVC Razor


Tags: html,css,asp.net-mvc,razor

Problem :

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.



Solution :

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")))


    CSS Howto..

    How to use CSS transition for existing list items to make room for new ones?

    CSS: How to select first element in each row?

    How to draw error icon with css only,exactly like in the image

    How to use @page CSS in ASP.NET MVC View

    How to locate element on a map by xpath or css selector

    How to select a td by position of its relative th?

    How to apply CSS style which will be ignored for tfoot or last TR

    How to click on and off submenu's using javascript

    how to create 100% vertical line in css

    IE8 and lower showing background white

    CSS media type: How to load CSS for mobile?

    How do I display div's next to each other within a wrapper div?

    HTML5 vs HTML4 - h1 tag rendered with extra space - how to remove?

    How to check if all CSS files have been downloaded to insert HTML using JavaScript?

    How to create table with resizable row and columns like HTML, CSS, JS boxes on JSFiddle?

    How to move this button?

    How to read inline styling of an element?

    How to “float” an absolutely positioned element div out of its container

    How to create a multiple-row section with auto-sized columns

    How to make menu bar with nested submenu css

    How to make my twitter bootstrap overlap all other elements?

    CSS list styling - how to reduce the distance between parent and children of the previous parent?

    How to change background color for only one bootstrap popover

    In LESS, how to rewrite this CSS composition style?

    Bootstrap 3 Glyphicons not showing correctly

    how to conditionally transform div to and from a state on multiple presses of same button

    CSS: How to create special shape

    Wordpress how to make sticky navigation menu / make the menu stick to the top all the time?

    How do I get a jquery function to only affect the child element of 'this'

    How can I organize my css rules?