MVC 3 Razor Meta Description / Keywords

user547043 picture user547043 · Feb 10, 2011 · Viewed 11.3k times · Source

What is the simplest way of getting meta description / keywords onto my _Layout page? Something similar to how you get the page Title would be nice. Such as

<title>@ViewBag.Title</title>
<meta name="keywords" content='@ViewBag.Keywords'/>
<meta name="description" content='@ViewBag.Description'/>

My view would look something like:

@{
    ViewBag.Title = "Contact Me";
    ViewBag.Keywords = "My, keyword, list, etc";
}

Answer

jgauffin picture jgauffin · Feb 10, 2011

Your view should not be responsible of that (do not add logic to views). Instead, it's the action method that should specify meta information.

Check my answer here: asp.net mvc - strategy for including SEO information such as meta keywords and descriptions

The answer still apply, although you should use ViewBag instead of ViewData.