2016-04-01 19 views
1

我想利用共享打開圖標記與我的asp.net網站mvc。我已經添加了元標記,但是在共享時,它仍然給出了我的網站的通用版本,而不是從元標記中提取信息。正確地分享使用開放圖的asp.netnet mvc

<meta property="og:url"    content="http://bandwagonbible.com/LifeHacks/LifeLessions" /> 
<meta property="og:type"    content="article" /> 
<meta property="og:title"    content="The 5 Essential Life Lessons They Don’t Teach in School" /> 
<meta property="og:description"  content="Just graduated and not sure that you learnt enough in class? These 5 secret lessons will help make your life a whole lot easier." /> 
<meta property="og:image"    content="http://bandwagonbible.com/Stories/LifeHacks/LifeLessons/Image1.jpg" />I 

我以前Facebook Developers - Object嘗試調試,但它說的meta標籤是在身體的某些原因。我可以問我如何正確使用與asp.net.net mvc打開圖我想也許是因爲它在身體的頭部?

錯誤信息Your page has meta tags in the body instead of the head. This may be because your HTML was malformed and they fell lower in the parse tree.

回答

4

如果它告訴你他們在身體,這可能是因爲他們是。你將需要讓他們進入<head>部分。

不知道如何您正在輸出標籤,很可能您只是直接在視圖中發出它們。您可能需要使用一個部分,以便將它們放在適當的位置。例如

_Layout.cshtml

<DOCTYPE html> 
<html lang="en"> 
<head> 
    <title>...</title> 
    <!-- ... --> 
    @RenderSection("OpenGraph", required: false) 
</head> 
<body> 
    @Html.RenderBody() 
</body> 
</html> 

MyView.cshtml

@model WhateverViewModel 
@section OpenGraph { 
    <meta property="og:..." content="..."> 
} 
@* Rest of view *@ 
+0

我絕對認爲這是在正確的軌道上!我剛剛開始asp .net mvc,請問我該如何修復RenderSection,它是無法識別的。我只看到RenderAction和RenderPartial – Master

+0

NVM!這實際上是@RenderSection謝謝! – Master

+0

@主持人:是的,哎呀。只是簡單的'@ RenderSection'。可能與'@ RenderBody'相同。 ;-) –