The name 'media' does not exist in the current context
Cssasp.net MvcHtmlasp.net Mvc-3Css Problem Overview
In an ASP.NET MVC 3 razor view, I have the code:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@media print
{
table { page-break-inside:auto; width: 100%; }
tr { page-break-inside:avoid; page-break-after:auto }
thead { display:table-header-group }
tfoot { display:table-footer-group }
}
</style>
</head>
<body>
<table>
However I got the error:
The name 'media' does not exist in the current context.
Thanks.
Css Solutions
Solution 1 - Css
The @
is a reserved character in Razor. But you can escape it using @@
:
@@media print
Solution 2 - Css
In razor views, @
is the magic character which preceeds code.
In your case, use 2 @@
. Otherwise razor will thing that it is some code/ expression.
@@media print.
Alternatively you can use Html.Raw
method also.
@Html.Raw("@")media print
You can do the same when printing twitter handle name which has the @
in it.
Here is a good msdn link to know more about razor syntax and here is one from phil hack