2010-12-02 122 views

回答

3

Meta標籤在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 
} 

這就是說,你應該更重要的是在看:

  • 關鍵字密度
  • 出境/入境鏈接
  • img alt標籤
  • 頁面標題
  • H1/H2內容
  • 長的URL細分和適用性

,因爲這些搜索引擎優化,這些天中發揮不斷增長的重要性。以上所有內容應該很容易在谷歌搜索。

+0

「從您的個人視圖中傳遞ViewData」,說什麼?行動方法會不會更有可能涉及? :) – bzlm 2010-12-02 13:08:47

0

我認爲吉姆過於複雜化它只是一點點佔位符 - 沒有必要。只是這樣做:

在_layout頭部分:

<meta name="description" [email protected]["Description"]/> 

在控制器:

ViewData["Description"] = "My site has all the goodies!!"; 

也沒必要將其包裝在一個條件;它不會拋出錯誤。如果您沒有在控制器中設置ViewData,則標籤將僅爲空:

<meta name="description"/> 
相關問題