我想從ViewBag對象傳遞數據到我的視圖上的JavaScript。MVC 3 - 將ViewBag內容分配給Javascript字符串
//In the controller
ViewBag.SomeUrl = "http://mydomain.com";
//In the View
<script type="text/javascript">
var theUrl = " @ViewBag.SomeUrl + ";
</script>
我遇到的問題是,下面的例子中,JS VAR 「theUrl」 設置爲:
「+ http://mydomain.com +」
省略級聯引號引起JavaScript來明顯地冒着冒險。那麼我怎麼能通過這個URL作爲我的JavaScript var的刺痛?
謝謝!
Doh .. cause Im a dork。謝啦 – Nick 2012-01-18 23:48:12