我創建了默認的ASP.NET MVC 3 Web應用程序。然後,我添加了三個CSS和三個js文件到\查看\ Shared_Layout.cshtml觀點:在ASP.NET MVC中組合和縮小JS和CSS
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/StyleSheet1.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/StyleSheet2.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/JScript1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/JScript2.js")" type="text/javascript"></script>
</head>
<body>
<div class="page">
<div id="header">
....
當我運行的應用程序,我的HTML代碼是
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
<link href="/Content/StyleSheet1.css" rel="stylesheet" type="text/css" />
<link href="/Content/StyleSheet2.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="/Scripts/JScript1.js" type="text/javascript"></script>
<script src="/Scripts/JScript2.js" type="text/javascript"></script>
</head>
<body>
<div class="page">
是否有可能在MVC的處理程序,以改變我的HTML輸出喜歡:
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<script src="js.axd=/Scripts/jquery-1.5.1.min.js,/Scripts/JScript1.js,/Scripts/JScript2.js" type="text/javascript"></script>
<link href="css.axd=/Content/Site.css,/Content/StyleSheet1.css,/Content/StyleSheet2.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="page">
所以鏈接js.axd=/Scripts/jquery-1.5.1.min.js,/Scripts/JScript1.js,/Scripts/JScript2.js
會將所有這些js文件的內容返回給瀏覽器,鏈接css.axd=/Content/Site.css,/Content/StyleSheet1.css,/Content/StyleSheet2.css
將返回所有css文件的內容。
我之前在ASP.NET中做過一些IHttpHandler,但無法弄清楚如何在MVC中這樣做,因爲我只是MVC中的入門者。
任何幫助和代碼示例將欣賞。 謝謝!