Alex Rivera | Logout

Script & CSS Registration Helper in ASP.NET MVC?

Asked 2008-11-26T04:37:42.690
10

I have tried to use ASP.NET MVC for a while, then I face a problem that I don't want to include all of my js and css in master page. But how can I register it in head of master page from my specific view?

Edit
Report

1 Answer

10

The default master page template includes a Content PlaceHolder for the head. If it doesn't you can easily add one:

<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server" />
</head>

Your views can then put anything they want in the head:

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script src="Scripts/myScripts.js" type="text/javascript"></script>
    <link href="Styles/myStyles.css" rel="stylesheet" type="text/css" />
</asp:Content>
answered 2008-11-26T23:23:06.023

Your Answer