当前位置: 代码迷 >> ASP.NET >> mvc3中ViewBag前台显示的有关问题
  详细解决方案

mvc3中ViewBag前台显示的有关问题

热度:1619   发布时间:2013-02-25 00:00:00.0
mvc3中ViewBag前台显示的问题
前台页面

@section Head{    
    <script type="text/javascript">
        alert@ViewBag.Test("");
    </script>
}


后台

ViewBag.Test = "123";


打开页面查看源文件
显示的是:alert@ViewBag.Test("");
我想要的:alert123("");

希望老鸟帮帮我
------最佳解决方案--------------------------------------------------------
alert@(ViewBag.Test)("");
------其他解决方案--------------------------------------------------------
改为
@section Head{     
    <script type="text/javascript"> 
        alert'@ViewBag.Test'(""); 
    </script> 
}

------其他解决方案--------------------------------------------------------
引用:
改为
@section Head{     
    <script type="text/javascript"> 
        alert'@ViewBag.Test'(""); 
    </script> 
}


不行啊哥们
源文件查看是:alert'123'("");
------其他解决方案--------------------------------------------------------
不太清楚你想要什么?
如果想输出到画面上就用  document.write('alert' + '@ViewBag.Test' + '("");'); 
如果想弹出对话框就要用  alert('@ViewBag.Test');
在javascript中如果想要使用ViewBag中的值,必须要加双引号或单引号才可以。
  相关解决方案