此视图中的分析器错误

时间:2014-01-20 23:39:31

标签: asp.net-mvc razor

试着用这段代码弄清楚我为什么会得到 Parser Error ,然后把我的大脑弄清楚:

    @foreach(var news in Model.News)
    {
        if (news.Order > 0)
        {
            <text>
    <div class="colPrincipal newsTop newsBlue">
        <article>
            <a href="news.html">
            </text>

            if (news.LayoutExibitionMainImage)
            {
            <text>
                <span class="newsImg">
                    <img src="~/Content/img/news/not2.jpg" alt="" title="" />
                </span>
            </text>
            }

            <text>
                <hgroup>
            </text>

            if (news.LayoutExibitionMainTitle)
            {
            <text>
                    <h1>
                        @Html.Raw(news.Title)
                    </h1>
            </text>
            }

            if (news.LayoutExibitionMainSummary)
            {
            <text>
                    <h2>
                        @Html.Raw(news.Summary)
                    </h2>
            </text>
            }

            <text>
                </hgroup>
                <span class="btnMais">Ler este artigo</span>
            </a>
        </article>
    </div>
            </text>
        }
    }

它在我的上一个<text>标记上抛出此错误:

enter image description here

有没有办法解决这个或更好的方法来打印HTML代码?我希望这不是一个愚蠢的问题,因为对我来说很奇怪。

1 个答案:

答案 0 :(得分:1)

试试这个,我认为你的所有文字标签都有问题。 hgroup标签中也不允许使用文本。

@foreach(var news in Model.News)
{
        @if (news.Order > 0)
        {
            <div class="colPrincipal newsTop newsBlue">
                <article>
                    <a href="news.html">
                        @if (news.LayoutExibitionMainImage)
                        {
                            <span class="newsImg">
                                <img src="~/Content/img/news/not2.jpg" alt="" title="" />
                            </span>
                        }

                        <hgroup>
                            @if (news.LayoutExibitionMainTitle)
                            {
                                    <h1>
                                        @Html.Raw(news.Title)
                                    </h1>
                            }

                            @if (news.LayoutExibitionMainSummary)
                            {
                                    <h2>
                                        @Html.Raw(news.Summary)
                                    </h2>
                            }
                        </hgroup>
                        <span class="btnMais">Ler este artigo</span>
                    </a>
                </article>
            </div>
        }
}