sergserg
sergserg

Reputation: 22224

Razor parsing something that I don't want it to parse. "Parser error"

I'm trying to add Facebook's comment count to my website. I'm using the Facebook comment plugin and would like to output the current count within my button. However, I'm getting a parser error from Razor. For some reason Razor is interpreting the -count closing tag as C# code.

Server Error in '/' Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

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

Here's my View:

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

Upvotes: 0

Views: 1507

Answers (2)

iBoonZ
iBoonZ

Reputation: 1035

Replace this

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

by this

  @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 will not try to parse it normally then

Upvotes: 1

Jomy John
Jomy John

Reputation: 6508

Try to put all contents in for each loop in <text></text> block .

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

<div class="post"> 

.......

</div>

</text>
}

Please also make make sure, you used facebook xml namespace in HTML tag

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

Matthew's comment also right. You have an extra / in fb tag

Upvotes: 0

Related Questions