MVC Razor與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語法中專門用來輸出字符串的


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章