css js bundle

本文介绍了MVC项目中布局文件(Layout.cshtml)的结构及其如何根据不同环境加载对应的样式表和脚本文件。通过条件语句实现开发环境使用未压缩版本而生产环境使用压缩版本的资源文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

------------- Layout.cshtml ------------- 
<!DOCTYPE html>


<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Title</title>
    
    @this.Html.Partial("BundleStylesFile")
    @this.RenderSection("Styles", required: false)
</head>
<body>
html code

    @this.Html.Partial("BundleScriptsFile")
    @this.RenderSection("Scripts", required: false)
    
    <script>
        ...
    </script>
</body>
</html>


------------- BundleStylesFile.cshtml ------------- 
<environment names="@EnvironmentName.Development">
    <link rel="stylesheet" href="~/css/bootstrap/bootstrap.css" asp-append-version="true" />
    ...
</environment>
<environment names="@EnvironmentName.Staging,@EnvironmentName.Production">
    <link rel="stylesheet" href="~/css/bootstrap/bootstrap.min.css" asp-append-version="true" />
    ...
</environment>
------------- BundleScriptsFile.cshtml ------------- 
<environment names="@EnvironmentName.Development">
    <script src="~/js/bootstrap/bootstrap.js" asp-append-version="true"></script>
    ...
</environment>
<environment names="@EnvironmentName.Staging,@EnvironmentName.Production">
    <script src="~/js/bootstrap/bootstrap.min.js" asp-append-version="true"></script>
    ...
</environment>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值