If you're working with ASP.NET MVC or ASP.NET Core using Razor pages and you want to put a CSS style within the page (CSS embed), you might stumble upon one of these following errors:
CS0103: The name 'media' does not exist in the current context.
CS0103: The name 'if' does not exist in the current context.
... And so on.
When something like that occurs, it probably means that you're using a CSS3 media query (or other CSS3 query related commands) such as this:
1 2 3 4 5 6 7 8 |
<style type="text/css"> @media print { .no-print, .no-print * { display: none !important; } } </style> |
... ignoring the fact that @ is a reserved character in Razor .cshtml pages.
Luckily enough, the fix is very simple: you can escape that char by doubling it, i.e. using @@, which Razor will print as a standard single @.
1 2 3 4 5 6 7 8 |
<style type="text/css"> @@media print { .no-print, .no-print * { display: none !important; } } </style> |
That's it: happy media-querying!