2012-10-10 30 views
0

我正在嘗試將Facebook的評論數添加到我的網站。我正在使用Facebook評論插件,並希望在我的按鈕內輸出當前計數。但是,我收到了來自Razor的解析器錯誤。出於某種原因,Razor正在將結束標記解釋爲C#代碼。Razor解析一些我不想分析的東西。 「解析器錯誤」

'/'應用程序中的服務器錯誤。

分析器錯誤

說明:該請求提供服務所需資源的分析過程中發生錯誤。請檢查以下特定的分析錯誤詳細信息並適當修改您的源文件。

Parser Error Message: Encountered end tag "div" with no matching start tag. 
Are your start/end tags properly balanced? 


Source Error: 


Line 42:    </div> 
Line 43:   </div> 
Line 44:  </div> 
Line 45: } 

Source File: /Views/Home/Index.cshtml Line: 44 

Version Information: Microsoft .NET Framework 
Version:4.0.30319; ASP.NET Version:4.0.30319.225 

這是我的觀點:

@using asdf.WebUI.Helpers 
@model IEnumerable<asdf.WebUI.Models.PostModel> 

@{ 
    ViewBag.Title = String.Format("adsf - {0}", DynamicContentHelper.GetDynamicHomePageQuip()); 
} 

@foreach (var post in Model) 
{ 
    <div class="post"> 
     <a href="@Url.Action("Details", "Post", new { id = post.PostId })"> 
      <img class="post-img" src="@post.ImageUrl" alt="@post.Description" title="@post.Description" />     
     </a>   
     <div class="detail"> 
      <div class="information"> 
       <h3 class="score">PUNTAJE: <span>234</span></h3> 

       <div class="vote"> 
        <button type="button" class="btn btn-success"><i class="icon-thumbs-up icon-white"></i> &nbsp; ME GUSTA</button> 
        <button type="button" class="btn btn-danger"><i class="icon-thumbs-down icon-white"></i> &nbsp; NO ME GUSTA</button> 
        <a class="btn btn-info comment-link" href="@Url.Action("Details", "Post", new { id = post.PostId })"> 

        <-- ERROR FIRES HERE!!!! --> 
        <i class="icon-comment icon-white"></i> &nbsp; &nbsp; COMENTARIOS &nbsp; &nbsp; <fb:comments-count href="http://asdf.net/bolivia/"/></fb:comments-count> 
        </a> 
       </div> 

       <div class="post-description"> 
        <blockquote class="pull-right"> 
         <p>@post.Description</p> 
         <small>imagen subida por: <a href="@Url.Action("Details", "Post", new { id = post.PostId })">@post.UserName</a></small> 
        </blockquote> 
       </div> 
      </div> 

      <div class="social"> 
       <a href="#" id="shareFacebook" data-popup-height="380" data-popup-width="660" data-url="http://www.facebook.com/sharer.php?u=http://www.asdf.net/bolivia/@post.PostId"> 
        <img src="@Url.Content("~/Public/assets/images/FB-share.png")"/> 
       </a> 

       <a href="#" id="shareTwitter" data-popup-height="270" data-popup-width="600" data-url="http://twitter.com/intent/tweet?url=http://www.asdf.net/bolivia/@post.PostId&[email protected]"> 
        <img src="@Url.Content("~/Public/assets/images/TW-share.png")"/> 
       </a> 
      </div> 
     </div> 
    </div> 
} 
+0

http://stackoverflow.com/替換此

<i class="icon-comment icon-white"></i> &nbsp; &nbsp; COMENTARIOS &nbsp; &nbsp; <fb:comments-count href="http://asdf.net/bolivia/"/></fb:comments-count> 

a/9795370/1182982這可能有幫助 – Yasser

+5

'/>'<---你有一個額外的/ – Matthew

+0

@Matthew你應該作爲答案張貼; *就是*答案 –

回答

0

儘量把所有的內容在每個循環中<text></text>塊。

@foreach (var post in Model) 
{ 
<text> 

<div class="post"> 

....... 

</div> 

</text> 
} 

請也使確保,你在HTML標籤

<html xmlns:fb="http://ogp.me/ns/fb#"> 

馬修的評論也對Facebook的使用XML命名空間。您在FB標籤有一個額外的/

+1

這裏的''並沒有太大的改變,因爲這個意圖對剃刀已經很明顯了。問題中唯一有趣的事情是額外的'/' –

1

@Html.Raw(<i class="icon-comment icon-white"></i> &nbsp; &nbsp; COMENTARIOS &nbsp; &nbsp; <fb:comments-count href="http://asdf.net/bolivia/"/></fb:comments-count>) 

剃刀不會嘗試分析它通常然後