ASP.NET MVC中Scripts.Render、Styles.Render的使用

1、配置BundleConfig.cs文件css


一、首先要在App_Start 裏面BundleConfig.cs 文件裏面 添加要包含的css文件

二、BundleConfig就是一個微軟新加的 一個打包的配置類

三、BundleConfig用來Add 各類Bundlehtml

四、BundleConfig配置信息如圖:jquery

 

public class BundleConfig {
      public static void RegisterBundles(BundleCollection bundles) {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"));
            bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include("~/Scripts/jquery-ui-{version}.js"));
            
            bundles.Add(new StyleBundle("~/Content1/css").Include("~/Content/site.css"));
            bundles.Add(new StyleBundle("~/Content1/themes/base/css").Include(
                        "~/Content/themes/base/jquery.ui.core.css",
                        "~/Content/themes/base/jquery.ui.resizable.css",
                        "~/Content/themes/base/jquery.ui.selectable.css",
                        "~/Content/themes/base/jquery.ui.accordion.css",
                        "~/Content/themes/base/jquery.ui.autocomplete.css",
                        "~/Content/themes/base/jquery.ui.theme.css"));
        }
    }



2、使用Scripts.Render、Styles.Render引用BundleConfig中的配置c#

 

一、在視圖文件中使用Scripts.Render()輸出腳本包,Styles.Render()輸出樣式包ui

二、Script文件引用:@Scripts.Render(virtualPath[,virtualPath1][,virtualPath2][,...])code

三、CSS文件引用:  @Styles.Render(virtualPath[,virtualPath1][,virtualPath2][,...])htm

四、實例ip

 

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content1/css")
</head>
<body>
    @RenderBody()

    @Scripts.Render("~/bundles/jqueryui")
</body>
</html>



參考資料:ASP.NET MVC中Scripts.Render、Styles.Render的使用   http://www.studyofnet.com/news/1178.html utf-8

相關文章
相關標籤/搜索