Reputation: 1375
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?
Upvotes: 3
Views: 3810
Reputation: 3455
Put this in your layout :
<head>
@RenderSection("MetaTags", required: false)
</head>
then in your razor page :
@section MetaTags
{
<meta name="description" content="test123" />
}
Upvotes: 4