This quick article is a response to a question I received today on Facebook. Please use the following procedure to add metatags on .cshtml pages.
When we create a MVC4 Application using an Internet Template we get a "Shared" folder inside the "Views" folder on the root and in the "Shared" folder you will find a layout page named "_Layout.cshtml". Open that file.
In the "_Layout.cshtml" page add a new section call inside the <head> tag, as given below:
In the above image you can see that a section call is not required; in other words whenever we need metatags on a page we can define.
Now, open you .cshtml page where you wish to add metatags and add the following section reference:
Now, open the page in a browser and you will see your metatags in action.
We can also make these metatags dynamic, in other words we can control them from controllers.
public ActionResult Index()
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
ViewBag.MetaKeywords = "abc";
ViewBag.MetaDescription = "abc";
<meta name='keywords' content='@ViewBag.MetaKeywords'/>
<meta name='description' content='@ViewBag.MetaDescription'/>