Razor View - Extra line at top of template

2019-08-29 16:25发布

问题:

@inherits VooDooBytes.Site
@{
Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

Is rendered as:

--- empty line ---
<!DOCTYPE etc...

My understanding is that this additional line can cause issues with elder versions of IE, forcing the browser into quirks mode.

This can be resolved, by putting the Layout deceleration and doctype on the same line, but that's a bit, well ugly. (although not as ugly as the transitional doctype, that was never a thing of beauty!)

回答1:

You could always invert the order in which those directives are appearing:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@inherits VooDooBytes.Site
@{ Layout = null; }
<html>


标签: razor