English 中文(简体)
ASP. NET MVC Razor Won t/60/8 My Valid Markup
原标题:ASP.NET MVC Razor Won t Accept My Valid Markup

I like the Razor syntax a lot, but it certainly falls short of perfect. For example, I have the following block of markup.

@if (Model.FeaturedDestinations != null && Model.FeaturedDestinations.Count() > 0)
{
    int column = 0;

    foreach (var d in Model.FeaturedDestinations)
    {
        column++;
        if (column > 4)
        {
            </div>
            @{ column = 1; }
        }
        if (column == 1)
        {
            @:<div class="row-fluid">
        }
        <div class="span3">
            @RenderDestination(d)
        </div>
    }
    </div>
}

因此,编辑给我一个粗略的栏目,显示我在开幕前有一个终点站:<代码><div> tag。 我可以这样生活。 但是,当我管理时,我实际上会遇到以下操作时间错误:

贴上“div”的末端标签,没有相应的开端。 您的开端/主角是否适当平衡?

显然,我不能生活在这个时代! 因此,在处理这一案件时是否有任何骗子? 我知道,就我所希望的标志而言,我做了些什么。 但是,Razor没有这样做,而是接手。

为什么黑板正在核对平衡标签的周期?

最佳回答

出于我不理解的原因,以下措施纠正了这一问题:

@if (Model.FeaturedDestinations != null && Model.FeaturedDestinations.Count() > 0)
{
    int column = 0;

    foreach (var d in Model.FeaturedDestinations)
    {
        column++;

        if (column > 4)
        {
            @:</div>
            column = 1;
        }

        if (column == 1)
        {
            @:<div class="row-fluid">
        }
        <div class="span3">
            @RenderDestination(d)
        </div>
    }
    @:</div>
}

Note the addition of @: before several tags. 我不知道为什么这些是必要的,即Razor强调,它承认这些是标签,而不是编码。

而且,为什么这造成错误消失? 造成时间错误的东西没有改变。 也许有人能够填满我身上的.子。

问题回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签