If you are working in ASP.NET MVC have questions like -
How to pass page's meta tags - adding Meta tags on Razor engine .cshtml Pages/adding it dynamically ?
Here is answer-

In this article we are going to see three ways of doing this-

 

 

  1. Using JQuery

  2. Using ViewBag

  3. Using @RenderSection and @Section

HTML_MetaTags_1

 

Approach 1 - Using Jquery :

 

A) In the "_Layout.cshtml" page add a new section call inside the <head> tag, as given below:

<head> 
 	<meta name="keywords" content="" />
 	<meta name="description" content="" />
</head>
B) In Page/View ( e.g Index )add following Script :
<script>
    $('meta[name=description]').attr('content', 'yourDescription');
    $('meta[name=keywords]').attr('content', 'yourKeyword');
</script>
 

 

Approach 2 - Using ViewBag:

 

A) In the "_Layout.cshtml" page add a new section call inside the <head> tag, as given below:
<head>
<meta name="description" property="og:description" content="@ViewBag.PageDescription" />
<meta name="keywords" property="keywords" content="@ViewBag.PageKeywords"/>
<head/>

 

 B) In Page/View ( e.g Index )add following section/code:

 

@{
////DESCRIPTION_VALUE and KEYWORD_VALUE - Can be replaced with model values  ViewBag.PageTitle = 'DESCRIPTION_VALUE';       //Model.Title;  ViewBag.PageKeywords ='KEYWORD_VALUE';  //Model.Keywords;
}

 

Approach 3 - Using @RenderSection and @Secton :

 

A) Declare meta tags in head section of "_Layout.cshtml" page as shown below
<head>
@RenderSection("META", required: false);
<head/>
B) In Page/View (e.g. Index) add following Section/Code
@Secton META{
@*///DESCRIPTION_VALUE and KEYWORD_VALUE - Can be replaced with model values (e.g. @Model.PageDescription) or ViewBag (e.g.@ViewBag.PageDescription)*@
<meta name="description" property="og:description" content="DESCRIPTION_VALUE" />
<meta name="keywords" property="keywords" content="KEYWORD_VALUE" />
}

Please like this article on social site if this worked for you… Coding is fun !!! Isn't it...