How to add meta tag in MVC

As we all know that Meta tag has very important roles in Search engine optimization and if we want to have out site listed with good ranking on search engines then we have to put meta tags

I have to add 10 meta tags to every page on my site, Web site having one layout.

Step 1: Disable metatag on layout page

  @this.RenderSection("MetaContent", false)

Step 2: Add Meta tag section on each page

@section MetaContent
{ 
}

Step 3: Add meta tag in this section

@section MetaContent
{ 
    <meta name="Title" content="Description" />
}

Now going ahead we have to add 10 meta tags on each page, to achieve this we are passing a list of Name and Content from controller to view and loop through the list to create dynamic meta tag as below

@section MetaContent
{
    @foreach (var item in Model.PageMeta)
    {
        <meta name="@item.Name" content="@item.Content"  />
    }
}

where PageMeta is a list consist of Name and Content.

Advertisements
This entry was posted in MVC and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s