I have several partial views with Javascript that I am trying to move to the bottom of the page. To do this I am trying to use a container in the master page
Master Page ->
<asp:ContentPlaceHolder ID="Foot" runat="server"></asp:ContentPlaceHolder>
Partial view(ascx)
<asp:Content ID="header" ContentPlaceHolderID="head" runat="server">
...
</asp:Content>
But I get this error
Parser Error Message: Content controls have to b开发者_如何学Pythone top-level controls in a content page or a nested master page that references a master page.
So how do I ensure that the Javascript for the partial view is at the bottom of the page? Especially in cases where the html layout needs to be at the top of the page?
The best approach is to use nested master pages instead of user controls.
In your master page:
<body>
...
<asp:ContentPlaceHolder ID="Scripts" runat="server" />
</body>
And in the page (aspx) that uses the partial (ascx):
<asp:Content ID="indexScripts" ContentPlaceHolderID="Scripts" runat="server">
<script type="text/javascript">
...
</script>
</asp:Content>
精彩评论