Ecco il codice ho attualmente:Razor Engine - Come posso rendere diversi tag body in base a condizioni diverse?
@{
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>
}
}
Ecco l'errore che restituisce quando il browser tenta di renderla:
parser messaggio di errore: Il blocco di codice manca una chiusura " } " carattere. Assicurati di avere un carattere "}" corrispondente per tutti i caratteri "{" di all'interno di questo blocco e che nessuno dei caratteri "}" viene interpretato come markup.
Che diamine? Sono stato in grado di farlo nella sintassi del template standard ASP.NET! Ecco cosa che sembrava:
<% // 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><% } %>
Si fa anche questo [schifezza convalida HTML] (http://joshuahayworth.com/wp-content/uploads/2011/10/razorEngineStackOverflowQuestion01.png) nell'IDE, che è fastidioso. –
Perché non usi CSS include? http://css-tricks.com/132-how-to-create-an-ie-only-stylesheet/. Basta definire uno stile per "corpo" in ciascuno di questi script. – jgauffin
Controllando ora! Grazie per il link. –