简体   繁体   中英

MVC Razor quirks mode - umbraco

I seem to have an obscure issue with a razor template forcing browsers into quirks mode. It is a simple razor template in umbraco 5. The following code makes chrome, firefox, IE all go into quirks mode:

@inherits RenderViewPage
@using System.Web.Mvc.Html;
@using Umbraco.Cms.Web;
@{
    Layout = "";
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html> 
<head>
  <meta charset="utf-8" />
  <title>Page title</title>
</head>
<body>



</body>
</html>

If I move the razor syntax completely or move it down so it is not before the doctype it goes into standards compliance mode. I've tried adding various X-UA-Compatible meta tags to no effect.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html> 
<head>
  <meta charset="utf-8" />
  <title>Page title</title>
</head>
<body>

@inherits RenderViewPage
@using System.Web.Mvc.Html;
@using Umbraco.Cms.Web;
@{
    Layout = "";
}

</body>
</html>

Anyone any ideas what could be the cause? It's as though the browsers think it is rendering something before the doctype but there is nothing I can see.

Thanks

You don't need a semi-colon on your @using statements, perhaps this is what the browser is seeing?

So eg

@using Umbraco.Cms.Web;

can just be

@using Umbraco.Cms.Web

Same here It looks like that it places extra chars (whitespace) right before opening tag < of doctype. I think that it is an editor bug.

Try to remove the opening "<" and insert it back and save after that. also doctype should be 1st line of the file.

The @ statements are translated to whitespace. The doctype is expected to be the first line of the document. In this case, the first line is blank, so the doctype is defined as an empty line, which triggers quirksmode .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM