在我的ASP.NET MVC 2的母版页太多的JavaScript和CSS文件? [英] Too many JavaScript and CSS files on my ASP.NET MVC 2 Master Page?

查看:498
本文介绍了在我的ASP.NET MVC 2的母版页太多的JavaScript和CSS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的ASP.NET MVC 2项目中使​​用EditorTemplate DateTime.ascx

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

<%@ 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 () {
        $('#<%: ViewData.TemplateInfo.GetFullHtmlFieldId(String.Empty) %>').AnyTime_picker({
            format: "%c/%d/%Y %l:%i %p"
        });
    });
</script>

本使用任何时间+™ JavaScript库jQuery的由Andrew M.安德鲁斯III。

This uses the Any+Time™ JavaScript library for jQuery by Andrew M. Andrews III.

我已经添加了这些库文件( anytimec.js anytimec.css )的&LT;头方式&gt;我的母版页部分

I've added those library files (anytimec.js and anytimec.css) to the <head> section of my master page.

而不是包括我的网站的每个网页上这些JavaScript和层叠样式表文件,我怎么能代替仅包括在需要它们的页面的.js和.css文件 - 页面的编辑DateTime类型值?

Rather than include these JavaScript and Cascading Style Sheet files on every page of my web site, how can I instead include the .js and .css files only on pages that need them--pages that edit a DateTime type value?

推荐答案

在你的主人:

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

而在将使用EditorTemplate /插件浏览次数(CSS):

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>

这篇关于在我的ASP.NET MVC 2的母版页太多的JavaScript和CSS文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆