Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Razor Mvc部分不是在头部渲染,而是在主体中渲染_Razor_Asp.net Core_Asp.net Core Tag Helpers - Fatal编程技术网

Razor Mvc部分不是在头部渲染,而是在主体中渲染

Razor Mvc部分不是在头部渲染,而是在主体中渲染,razor,asp.net-core,asp.net-core-tag-helpers,Razor,Asp.net Core,Asp.net Core Tag Helpers,我在_布局的head部分遇到了@RenderSection的一个奇怪行为 @section AddToHead{ <meta name="test" /> <open-graph og-title="@Model.Test.OG.Title" og-image="@Model.Test.OG.Image" og-url="@Model.Test.OG.Url" og-type="@Model.Test.OG.Type"></open-graph&g

我在_布局的head部分遇到了@RenderSection的一个奇怪行为

@section AddToHead{ 
    <meta name="test" />
    <open-graph og-title="@Model.Test.OG.Title" og-image="@Model.Test.OG.Image" og-url="@Model.Test.OG.Url" og-type="@Model.Test.OG.Type"></open-graph>
}
@section AddToHead{
}
  • meta=>是纯html
  • open graph=>是一个返回html的标记帮助程序
  • 并添加在_布局上

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        @await RenderSectionAsync("AddToHead", required: false)
    </head>
    
    
    @等待RenderSectionAsync(“AddToHead”,必需:false)
    
    我已经尝试了RenderSectionAsync和RenderSection。没有区别

    当我检查第页的结果时,结果如下(完全不同的结果)

    查看源代码

    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    
        <meta name="test" />
        <div><meta property='og:title' content='TestTitle' /><meta property='og:type' content='Article' /><meta property='og:url' content='TestURL' /><meta property='og:image' content='TestBild' /></div>
    </head>
    
    
    
    开发工具

    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    
        <meta name="test" />
    
    </head>
    <body>
      <div><meta property='og:title' content='TestTitle' /><meta property='og:type' content='Article' /><meta property='og:url' content='TestURL' /><meta property='og:image' content='TestBild' /></div>
    </body>
    
    
    
    Facebook就像开发者工具一样看待我的网站


    我做错了什么?这可能吗?

    开发人员工具显示浏览器如何解释HTML,这就是为什么您看到查看源代码和开发人员工具之间的差异


    至于发生这种情况的原因,
    中的
    标记是有问题的。现在的大多数浏览器都会将那些
    标记解释为它们就好像它们在身体里一样。如果要在没有周围div的情况下渲染
    标记,一切都应该很好。

    谢谢Taylor。很高兴知道。