这是我现在的代码:
@{ if (Request.Browser.Browser == "IE") { if (Request.Browser.MajorVersion == 7) { <body class="ie7"> } if (Request.Browser.MajorVersion == 8) { <body class="ie8"> } if (Request.Browser.MajorVersion == 9) { <body class="ie9"> } if (Request.Browser.MajorVersion > 9) { <body> } } else { <body> } }
这是浏览器尝试呈现时返回的错误:
Parser Error Message: The code block is missing a closing “}”
character. Make sure you have a matching “}” character for all the
“{” characters within this block,and that none of the “}” characters
are being interpreted as markup.
有没有搞错?我能够在标准的ASP.NET模板语法中做到这一点!这就是这样的:
<% // Adaptation of paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ if ( (Request.Browser.Browser == "IE") && (Request.Browser.MajorVersion == 7) ) { %><body class="ie7"><% } %> <% if ( (Request.Browser.Browser == "IE") && (Request.Browser.MajorVersion == 8) ) { %><body class="ie8"><% } %> <% if ( (Request.Browser.Browser == "IE") && (Request.Browser.MajorVersion == 9) ) { %><body class="ie9"><% } %> <% if ( (Request.Browser.Browser == "IE") && (Request.Browser.MajorVersion > 9) ) { %><body><% } %> <% if (Request.Browser.Browser != "IE") { %><body><% } %>
解决方法
更好的选择可能是在视图顶部声明一个ieClass变量,然后在body标签中引用它.
@{ string ieClass = ""; if (Request.Browser.Browser == "IE") { if (Request.Browser.MajorVersion == 7) { ieClass="ie7"; } else if (Request.Browser.MajorVersion == 8) { ieClass="ie8"; } else if (Request.Browser.MajorVersion == 9) { ieClass="ie9"; } } }
…
<body class="@ieClass">