在ASP.NET MVC中使用已编译的全局资源,可以遵循以下步骤:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
// 添加已编译的全局资源引用
ClientScript.RegisterClientScriptResource(typeof(Resources.Resource), "Resources.Resource.js");
ClientScript.RegisterClientScriptResource(typeof(Resources.Resource), "Resources.Resource.css");
}
@using Resources
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
// 添加已编译的全局资源引用
<link href="@Url.Content("~/Content/Resource.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/Resource.js")" type="text/javascript"></script>
</head>
<body>
// ...
</body>
</html>
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
ViewBag.Title = "My View";
}
<h2>My View</h2>
// 添加已编译的全局资源引用<script src="@Url.Content("~/Scripts/Resource.js")" type="text/javascript"></script>
通过以上步骤,可以在ASP.NET MVC中使用已编译的全局资源。
领取专属 10元无门槛券
手把手带您无忧上云