How do I inject a script tag such as
<script src="somejsfile"></script>
or
<script type="text/javascript>some javascript</script>
into the head tag of a page from a partial view?
Update: Answer for the old question This is about ASP.NET MVC. We can use the RenderSection. Here the sample for MVC 3 using Razor view engine:
layout view or master page:
<html>
<head>
<script ...></script>
<link .../>
@RenderSection("head")
</head>
<body>
...
@RenderBody()
...
</body>
</html>
View, e.g. 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. -->