日期:2014-05-17  浏览次数:20481 次

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中的值,必须要加双引号或单引号才可以。