I have a simple View and I wish to add a JQuery DatePicker JavaScript to this view (and not every view, via a masterpage).
I’m not sure what is the best way to do this.
Second, I’m conscious of where/when my JavaScript loads. I’m a fan of YSlow and it recommends that I add any scripts to the bottom of the page, which I do.
So, how could I do both?
Here’s the view:
<%@ Page Language='C#' MasterPageFile='~/Views/Shared/Site.Master' Inherits='System.Web.Mvc.ViewPage' %> <asp:Content ID='Content1' ContentPlaceHolderID='MainContent' runat='server'> <h2>Index</h2> <% using (Html.BeginForm()) {%> <p> <label for='StartDate'>Start Date:</label> <!-- JQuery DatePicker to be added, here. --> </p> <% } %> </asp:Content>
One way is put a content placeholder at the bottom of your master page, then the specific slave page that needs the javascript can specify the placeholders contents as the required javascript. Other pages that don’t need the javascript simply don’t specify any content for the placeholder.