2

I use Visual Studio 2013 project template to create MVC web site. It use a _Layout .cshtml to include header information and have 5 more pages(views) such as product, service , contact us etc. My page Layout.cshtml is look like this

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title – ABC Technology</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    @Html.Partial("TopMenu")
    @RenderBody()
</body>

Each of those pages(views) use _layout.cshtml. Now I want to add meta description and meta keyword for each page based on the content in that page. I do not want to skip using page layout and add <head> to each page.

I am new to ASP.NET MVC 5.

Can someone please help?

Dush
  • 912
  • 19
  • 25
  • @Erick, I think you may have misunderstood the question, the question in the link is completely different and no explanation about my problem of adding metadata dynamically. I searched entire web and the stacoverflow and found nothing related to it and the link doesn't answer the question. – Dush Mar 16 '15 at 04:19

1 Answers1

2

Put this in your layout :

<head>
    @RenderSection("MetaTags", required: false)
</head>

then in your razor page :

@section MetaTags
{
    <meta name="description" content="test123" />
}
warheat1990
  • 2,827
  • 2
  • 28
  • 62