0

我正在尝试将 Facebook 的评论计数添加到我的网站。我正在使用 Facebook 评论插件,并希望在我的按钮中输出当前计数。但是,我收到来自 Razor 的解析器错误。出于某种原因,Razor 将-count结束标记解释为 C# 代码。

“/”应用程序中的服务器错误。

解析器错误

说明:解析服务此请求所需的资源时出错。请查看以下特定的解析错误详细信息并适当地修改您的源文件。

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&text=@post.Description">
                    <img src="@Url.Content("~/Public/assets/images/TW-share.png")"/>
                </a>
            </div>
        </div>
    </div>
}
4

2 回答 2

1

替换这个

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

这样

  @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>)

Razor 不会尝试正常解析它

于 2012-10-10T06:56:58.527 回答
0

尝试将所有内容放入<text></text>block 中的每个循环。

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

<div class="post"> 

.......

</div>

</text>
}

另请确保您在 HTML 标记中使用了 facebook xml 命名空间

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

马修的评论也对。你有一个额外/的 fb 标签

于 2012-10-10T05:42:37.610 回答