Html 当前上下文中不存在名称“媒体”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13612413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:08:02  来源:igfitidea点击:

The name 'media' does not exist in the current context

cssasp.net-mvchtmlasp.net-mvc-3

提问by McGarnagle

In an ASP.NET MVC 3 razor view, I have the code:

在 ASP.NET MVC 3 razor 视图中,我有代码:

<!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.

谢谢。

回答by McGarnagle

The @is a reserved character in Razor. But you can escape it using @@:

@是剃刀保留字符。但是你可以使用@@以下方法来逃避它:

@@media print

回答by Shyju

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.

在您的情况下,请使用 2 @@。否则剃刀会认为它是一些代码/表达式。

@@media print.

Alternatively you can use Html.Rawmethod also.

或者,您也可以使用Html.Raw方法。

@Html.Raw("@")media print

You can do the same when printing twitter handle name which has the @in it.

在打印其中包含 twitter 句柄名称时,您可以执行相同的操作@

Hereis a good msdn link to know more about razor syntax and hereis one from phil hack

是一个很好的 msdn 链接,可以了解有关 razor 语法的更多信息,是 phil hack 的一个链接