[英]MVC and Meta Tags for Search Engine Optimization
我正在制作mvc2。 我想要使用元標記。 我對meta標簽和seo還是陌生的。 如何在我的頁面上使用元標記? 在MVC上使用元標記的最佳方法是什么?
這些天來,元標記在SEO中的作用越來越小。
但是,相對於MVC,您可以按照以下幾行設置母版頁:
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="TitleContent" runat="server" />
</title>
<asp:ContentPlaceHolder
ID="MetaPlaceHolder" runat="server">
<meta name="keywords" content="<%= ViewData["keywords"] %>" />
<meta name="description" content="<%= ViewData["description"] %>" />
</asp:ContentPlaceHolder>
// lots os stuff missed out!!
</head>
<body>// more suff missed etc</body>
然后從您的各個控制器操作中傳遞ViewData來填充“關鍵字”和“說明”部分。 還有其他方法,但是這種方法很容易啟動和運行,而不會嚴重破壞現有代碼庫。
用法-將以下內容添加到每個必需的控制器操作中
public ActionResult Index()
{
// data would obviously come from some datastore but hardcoded for now below
ViewData["keywords"] = "speed, camera, action";
ViewData["description"] = "crime dun wrong";
// other stuff happening too
}
也就是說,您應該更重要地關注以下方面:
因為這些在SEO中越來越重要。 以上所有內容都可以在Google上輕松搜索。
我認為Jim只是用占位符使它過於復雜了-沒必要。 只要這樣做:
在_Layout頭部分中:
<meta name="description" content=@ViewData["Description"]/>
在控制器中:
ViewData["Description"] = "My site has all the goodies!!";
也無需將其包裝成條件包裝; 它不會拋出錯誤。 如果您未在控制器中設置ViewData,則標記將為空:
<meta name="description"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.