MVCRazor与javascript混编(js中嵌入razor)

其中的关键是输出js上的纯文本内容,让浏览器解析为其中的js代码

 

<script>
    BUI.use(‘common/main’,function(){
        var config = [
        {
            id: ‘1’,
            menu:
            [
         @{ 
             int ruiyalel = (int)Session[“ruiyaLev”];
             int happyfamilylel = (int)Session[“happyfamilyLev”];

             if (ruiyalel > 0) {
              <text>
              {
                  text: ‘瑞亚官网’, items: [{ id: ‘3’, text: ‘瑞亚新闻’, href: ‘DBSystem/ruiya/News’ }, ]
              },
              </text>
             }
             if (happyfamilylel > 0){
              <text>
              {
                  text: ‘全家乐’, items: [{ id: ‘4’, text: ‘新闻管理’, href: ‘DBSystem/happyfamily/News’ },
                                         { id: ‘5’, text: ‘活动管理’, href: ‘DBSystem/happyfamily/Activity’ },
                                         { id: ‘6’, text: ‘综合管理’, href: ‘DBSystem/happyfamily/GeneralMes’ }, ]
              },
              </text>
             }

         }            
            ]

        }];

        new PageUtil.MainPage({
            modulesConfig : config
        });

    });
    </script>

 

 

@:表示后面直接输出字符串

          <text></text>表示里面输出的是字符串

          两种方式可以任选一种,注意<text>不是html标签,他是razor语法中专门用来输出字符串的

原文链接:https://www.cnblogs.com/sjqq/p/9031530.html
本文来源 爱码网,其版权均为 原网址 所有 与本站无关,文章内容系作者个人观点,不代表 本站 对观点赞同或支持。如需转载,请注明文章来源。

© 版权声明

相关文章