code_junkie

How to pass page's meta tags in ASP.NET MVC?

Nov 11th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <head>
  2. <asp:ContentPlaceHolder ID="cphHead" runat="server">
  3. <title>Default Title</title>
  4. <meta name="description" content="Default Description" />
  5. <meta name="keywords" content="Default Keywords" />
  6. </asp:ContentPlaceHolder>
  7. </head>
  8.  
  9. <asp:Content ID="headContent" ContentPlaceHolderID="cphHead" runat="server">
  10. <title>Page Specific Title</title>
  11. <meta name="description" content="Page Specific Description" />
  12. <meta name="keywords" content="Page Specific Keywords" />
  13. </asp:Content>
  14.  
  15. public class BaseViewData
  16. {
  17. public string Title { get; set; }
  18. public string MetaKeywords { get; set; }
  19. public string MetaDescription { get; set; }
  20. }
  21.  
  22. public partial class Site : System.Web.Mvc.ViewMasterPage<BaseViewData>
  23. {
  24. }
  25.  
  26. <title><%=ViewData.Model.Title %></title>
  27. <meta name="keywords" content="<%=ViewData.Model.MetaKeywords %>" />
  28. <meta name="description" content="<%=ViewData.Model.MetaDescription %>" />
Add Comment
Please, Sign In to add comment