Home Mvc section not rendered in head but in body
Reply: 0

Mvc section not rendered in head but in body

user2001
1#
user2001 Published in June 22, 2018, 11:31 am

I encountered a strange behavior for @RenderSection in the head section of _Layout.

@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>
}
  1. meta => is plain html
  2. open-graph => is a taghelper which returns html

and added on _Layout

<!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>

I tried already with RenderSectionAsync and RenderSection. No difference.

When I check the result on page it is as follows (total different result)

View Source Code

<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>

Developer Tools

<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 sees my site like Developer Tools does.

What I'm doing wrong? Is this even possible?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312308 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO