AutumnalRiver

我喜欢秋天,因为那是丰收的时节。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ASP.NET MVC 中 Master Page 引用脚本错误

Posted on 2008-10-27 11:31  秋江  阅读(2971)  评论(24编辑  收藏  举报

在ASP.NET MVC 中,Master Page 在其 Head 节中可以引用 CSS 以及 JS 文件。但是不知为什么,CSS 文件可以自动解析为客户端可用的引用路径,而 JS 文件则原封不动的使用设计时设定的路径,即使使用 "~/" 也不行。

怎么办呢?我想到了用 Helper 方法: Url.Content:

Code
结果报错:
Code

没办法了,Google一把,关键词就是The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

终于找到解决方法,特意共享给大家,原文:The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

虽然其场景并非 MVC,但值得借鉴。

我的修改如下

Code

OK!问题解决!