剃刀解析我不想要解析的东西。 “分析器错误”

时间:2012-10-10 04:35:34

标签: c# asp.net-mvc razor

我正在尝试将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>
}

2 个答案:

答案 0 :(得分: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不会尝试正常解析它

答案 1 :(得分:0)

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

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

<div class="post"> 

.......

</div>

</text>
}

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

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

马修的评论也是对的。您在fb标签中有额外的/