3

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?

1
  • @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. Commented Mar 16, 2015 at 4:19

1 Answer 1

4

Put this in your layout :

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

then in your razor page :

@section MetaTags
{
    <meta name="description" content="test123" />
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.