如何注入脚本标记,如
<script src="somejsfile"></script>
或
<script type="text/javascript>some javascript</script>
从局部视图添加到页面的head标记中?
更新:老问题的答案这是关于ASP.NET MVC的。我们可以使用RenderSection。以下是使用Razor视图引擎的MVC 3的示例:
布局视图或母版页:
<html>
<head>
<script ...></script>
<link .../>
@RenderSection("head")
</head>
<body>
...
@RenderBody()
...
</body>
</html>
视图,例如Home:
@section head{
<!-- Here is what you can inject the header -->
<script ...></script>
@MyClass.GenerateMoreScript()
}
<!-- Here is your home html where the @RenderBody() located in the layout. -->
发布于 2009-11-20 12:24:04
分部视图是UserControl
%s。不能使用ClientScriptManager
的RegisterClientScriptInclude
方法吗
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
Page.ClientScript.RegisterClientScriptInclude("some key", "http://website/javascript.js");
}
https://stackoverflow.com/questions/1768132
复制相似问题