Asp.net mvc 3 如何在foreach中的Razor if语句中向页面添加html?

Asp.net mvc 3 如何在foreach中的Razor if语句中向页面添加html?,asp.net-mvc-3,Asp.net Mvc 3,如何从@foreach()中的if()中向页面添加html。我没有得到任何具体的错误,只是不需要第二个if()。它像文字一样写出来 这是我尝试过的,但没有运气 @foreach (var item in Model) { if (count % 4 == 0 || totaltCount == 1) { <div class="in-instructor-container"> }

如何从
@foreach()
中的
if()
中向页面添加html。我没有得到任何具体的错误,只是不需要第二个
if()
。它像文字一样写出来

这是我尝试过的,但没有运气

@foreach (var item in Model)
    {
        if (count % 4 == 0 || totaltCount == 1)
        {
        <div class="in-instructor-container">
            }
            <div class="in-instructor">
                <h3>@item.Name</h3>
                @item.Information
            </div>
        if ((count - 1) % 3 == 0 || count == totaltCount) {
        </div>
        }

        count++;
    }
@foreach(模型中的变量项)
{
如果(计数%4==0 | |总计数==1)
{
}
@项目名称
@项目.资料
如果((计数-1)%3==0 | |计数==TotalCount){
}
计数++;
}
我的html是这样的

        <div class="in-instructor-container">
            }
            <div class="in-instructor">

                <h3>Test Person 0</h3>
                bla bla bla bla bla bla bla
            </div>
        if ((count - 1) % 3 == 0 || count == totaltCount) {
        </div>

}
测试人员0
呜呜呜呜呜呜呜呜呜呜
如果((计数-1)%3==0 | |计数==TotalCount){

您需要在if语句中的html前面添加@::

@foreach (var item in Model)
{
    if (count % 4 == 0 || totaltCount == 1)
    {
        @:<div class="in-instructor-container">
    }
        <div class="in-instructor">
            <h3>@item.Name</h3>
            @item.Information
        </div>

    if ((count - 1) % 3 == 0 || count == totaltCount) {
        @:</div>
    }

    count++;
}
@foreach(模型中的变量项)
{
如果(计数%4==0 | |总计数==1)
{
@:
}
@项目名称
@项目.资料
如果((计数-1)%3==0 | |计数==TotalCount){
@:
}
计数++;
}

我从stackoverflow问题中找到了这个解决方案

我不是那个否决你的人,但是如果没有更多的信息,你就不会得到任何帮助。有错误吗?问题是什么?如果可以的话,我会对此投上一百万次票,因为stackoverflow问题上有太多的答案不适合这个问题。我想,第二个反对条件必须是=>如果((计数+1)%4==0)|计数==TotalCount)