Too many JavaScript and CSS files on my ASP.NET MVC 2 Master Page?

后端 未结 2 421
别那么骄傲
别那么骄傲 2021-01-15 12:39

I\'m using an EditorTemplate DateTime.ascx in my ASP.NET MVC 2 project.

<%@ Control Language=\"C#\" Inherits=\"System.Web.Mvc.ViewUserControl         


        
相关标签:
2条回答
  • 2021-01-15 13:19

    In your master:

    <asp:ContentPlaceHolder ID="Scripts" runat="server" />
    

    And in the Views (aspx) that will use the EditorTemplate/plugin:

    <asp:Content ID="indexScripts" ContentPlaceHolderID="Scripts" runat="server">
        <script type="text/javascript" src="anytime.js"></script>
    </asp:Content>
    
    0 讨论(0)
  • 2021-01-15 13:39

    First idea that comes to mind =>

    Template:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime>" %>
    <%: Html.TextBox(String.Empty, Model.ToString("M/dd/yyyy h:mm tt")) %>
    <script type="text/javascript">
        $(function () {
            MakeSureAnyTimeIsIncluded();
            $('#<%: ViewData.TemplateInfo.GetFullHtmlFieldId(String.Empty) %>').AnyTime_picker({
                format: "%c/%d/%Y %l:%i %p"
            });
        });
    </script>
    

    masterpage or shared external JS file:

      function MakeSureAnyTimeIsIncluded(){
        if (!anyTimeIsIncluded)
          //document.write(<script src="correct url") something like that
          anyTimeIsIncluded=true;
      }
    
    0 讨论(0)
提交回复
热议问题