Skip to content

How can I pass ViewData to _Layout.cshtml? Is it possible? #133

@won5572

Description

@won5572

HydroComponent cshtml

ViewData.Add("TitleMetaTags", new TitleMetaTags
{
	Title = "Test 111",
	Description = "Description",
	OgUrl = "https://example.com/",
	OgTitle = "Test 111 — Home",
	OgDescription = "Description",
	OgImage = "https://example.com/images/banner.png",
	OgType = "website"
  });

_Layout.cshtml

<title>@Html.Raw(Model.Title)</title>
<meta name="description" content="@Html.Raw(Model.Description)" />
<meta property="og:url" content="@Html.Raw(Model.OgUrl)" />
<meta property="og:title" content="@Html.Raw(Model.OgTitle)" />
<meta property="og:description" content="@Html.Raw(Model.OgDescription)" />
<meta property="og:site_name" content="@Html.Raw(Model.SiteName)" />
<meta property="og:type" content="@Html.Raw(Model.OgType)" />
@if (!string.IsNullOrEmpty(Model.OgImage))
{
	<meta property="og:image" content="@Html.Raw(Model.OgImage)" />
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions