对应打算用作页面布局模板的任何内容都必须来自LayoutComponentBase
类。为了表明您希望页面内容出现的位置,您只需输出Body
属性的内容。
@inherits LayoutComponentBase
<div class="main">
<header>
<h1>This is the header</h1>
</header>
<div class="content">
@Body
</div>
<footer>
This is the footer
</footer>
</div>
请注意,这不是整个HTML页面。 Blazor布局仅在wwwroot \ index.html
页面中定义Blazor的HTML部分中起作用,在默认Blazor应用程序中,这就是<app>
元素中的所有内容。除了使用JavaScript Interop,目前无法在此范围之外更改HTML元素的属性。