0

I want to add some scripts at the head of a website, written in aspx. However, aspx pages do not have head part, but it is generated afterwards. how I can write something at the head of a website written in aspx?

Jim Blum
  • 2,656
  • 5
  • 28
  • 37
  • What do you mean by that "they do not have head part"? You can simply put inside head tag in aspx pages. – tilda Jan 12 '14 at 03:07
  • Thanks a lot @tilda for your comment. I am using ASP.NET MVC4. There is a master page, but each file individually, has no a head part. I want to add something at the head part for a specific aspx page. – Jim Blum Jan 12 '14 at 03:17
  • Hope this thread helps! http://stackoverflow.com/questions/4311783/asp-net-mvc-3-razor-include-js-file-in-head-tag – tilda Jan 12 '14 at 03:20

1 Answers1

2

You will have a layout page that has a head part. In that render an optional section for your scripts.

In your layout file:

<head>
    ...
    @RenderSection("scripts", required: false)
</head>

And in your view in which you want to add scripts to the head part of the page do this:

@section scripts
{
   @Scripts.Render("~/YourScript.js")
}
Saravana
  • 37,852
  • 18
  • 100
  • 108
  • @JimBlum ideally though you'd want to do that just before your `

    ` tag. Outside of modernizr, there usually isn't a reason to put scripts in the `head` tag.

    – MikeSmithDev Jan 12 '14 at 04:22