og:image from Partial View

632 Views Asked by At

I am in a partial View, and I want to put open graph in the head

But head declared in the _Layout.cshtml

how do I put this

<meta property="og:image" content="@Model.ThumbnailUrl" />

in the head from _Layout.cshtml, if I have the Value in the Model? (in a partial view)

1

There are 1 best solutions below

0
On

Found the answer!

_Layout.cshtml:

<head>
    @RenderSection("OpenGraphProtocol", false)
</head>

PartialView.cshtml:

@section OpenGraphProtocol {
    <meta property="og:image" content="@Model.ThumbnailUrl" />
    <meta property="og:title" content="@ViewBag.Title" />
   }