加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-4 – MVC 4 Razor如果拆分div标签

发布时间:2020-12-15 20:26:49 所属栏目:asp.Net 来源:网络整理
导读:我有以下MVC 4剃须刀代码: @for (int i = 1; i = 100; i++) { if (currentCol == 1) { Html.Raw("div class=row"); @*Need to do this because can't have a open div within a if compiler doesnt like it *@ } if (currentCol == maxCol) { Html.Raw("/di
我有以下MVC 4剃须刀代码:
@for (int i = 1; i <= 100; i++) {

    if (currentCol == 1) {
        Html.Raw("<div class=row>");
    @*Need to do this because can't have a open div within a if compiler doesnt like it *@
    } if (currentCol == maxCol) {
        Html.Raw("</div>");
    }
    currentCol++;
}

我基本上试图通过if语句的不同路径中的开始和结束标签有条件地生成每个div类行的内容.当我使用直接的HTML,编译器不喜欢它,并认为括号是关闭的.看来Html.Raw是我在线搜索的解决方案,但是当我使用Html.Raw时,当我查看源代码时,div不会显示.

有人知道发生了什么吗?

解决方法

尝试使用@前缀Html.Raw调用:
@for (int i = 1; i <= 100; i++) 
{
    if (currentCol == 1) 
    {
        @Html.Raw("<div class=row>");
    } 
    if (currentCol == maxCol) 
    {
        @Html.Raw("</div>");
    }
    currentCol++;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读