大纲
我试图弄清楚如何在 ASP.NET MVC3 中向 iFrame 注入或定义样式表。我已经浏览了有关上述主题的现有线程,但没有一个适合我的情况。我有一个解决方案定义了一个用户控件(ParitalShimViewControl),它在 aspx 中呈现 .CSHTML 页面。使用该解决方案中的 dll,我将其引用到另一个解决方案(主框架所在的位置)并集成到主解决方案中。所有的 css、js 文件只保存在主解决方案中。
问题
我所做的是,我定义了一些功能(创建控制器、视图和模型)并使用 PartialShimControl 渲染它并将其映射到其中一个 aspx 页面中的主要解决方案。在这里,我需要使用 iFrame 调用一些跨域服务并在 .CSHTML 文件(即视图)上呈现结果,但是需要使用样式表正确格式化结果,不幸的是我无法引用样式表在视图中,因为它们被放置在主解决方案中。
问题
希望要求明确。如何在主要解决方案中或任何可能的方式中引用 iFrame 中的那些 css?
希望我听起来不会太混乱:(
代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/X.master"
AutoEventWireup="true" CodeBehind="X.aspx.cs" Inherits="Online.Web.Pages.X" %>
<%@ Register Assembly="Online.CommonFramework" Namespace="Online.CommonFramework.BaseClasses"
TagPrefix="CFBase" %>
<%@ Register Src="~/UserControls/Shims/PartialViewShimControl.ascx" TagName="PartialViewShim" TagPrefix="UC" %>
<%@ Register Assembly="Online.Web" Namespace="Online.Web.ProviderWebParts.DashBoard"
TagPrefix="DashBoardWebParts" %>
<%@ Register Assembly="Online.Web" Namespace="Online.Web.WebParts"
TagPrefix="WebParts" %>
<asp:Content ID="HeadContent" runat="server" ContentPlaceHolderID="Head">
<link href="/Content/css/Core.css" rel="stylesheet" type="text/css" />
<link href="/Content/css/Home.css" rel="stylesheet" type="text/css" />
<link href="/Content/css/Pods.css" rel="stylesheet" type="text/css" />
<%--<link href="/Pages/CSS/layoutHome.css" rel="stylesheet" type="text/css" />
<link href="/Pages/CSS/Master0.css" rel="stylesheet" type="text/css" />
<link href="/Pages/CSS/compNewLexis0.css" rel="stylesheet" type="text/css" />
<link href="/Pages/CSS/Search0.css" rel="stylesheet" type="text/css" />--%>
</asp:Content>
<asp:Content ID="MedLitBodyContent" ContentPlaceHolderID="LandingBody" runat="server">
<%--<script type="text/javascript" src="JS/api/N.js"></script>
<script type="text/javascript" src="JS/api/Utils.js"></script>
<script type="text/javascript" src="JS/apiWebStorage.js"></script>
<script type="text/javascript" src="JS/vendor/VendorMaster0.js"></script>
<script src="JS/api/SearchResults.js" type="text/javascript"></script>
<script src="JS/vendor/backbone.js" type="text/javascript"></script>
<script src="JS/vendor/handlebars.js" type="text/javascript"></script>
<script src="JS/vendor/jquery-1.7.1.js" type="text/javascript"></script>
<script src="JS/vendor/underscore.js" type="text/javascript"></script>--%>
<script type="text/javascript" src="/MedLit/Content/js/LA.MedLit.Core.js"></script>
<script type="text/javascript" src="/MedLit/Content/js/LA.MedLit.MedicalResearch.js">
</script>
<script type="text/javascript" src="/MedLit/Content/js/LA.MedLit.CaseValueAssessment.js"></script>
<script type="text/javascript" src="/X/Content/js/L.X.BrowseTopics.js">
</script>
<script type="text/javascript" src="/X/Content/js/L.X.ToPDF.js"></script>
<script type="text/javascript">
$LAB
.script('/JS/vendor/VendorMaster1.js')
.script('/JS/api/N.Advance.Ajax.js').wait()
.script('/JS/api/N.Advance.WebStorage.PageData.js')
.script('/JS/api/N.Advance.Popup.js')
.script('/JS/api/N.Advance.Events.js')
.script('/JS/api/N.Advance.UI.js')
.script('/JS/api/N.Advance.Transactional.js')
.script('/JS/api/N.Advance.Middleware.js')
.script('/JS/api/N.Advance.Ready.js')
.wait(function () {
$(LN.Advance.Ready.init);
});
</script>
<asp:ProxyWebPartManager ID="WProxyManager" runat="server">
<StaticConnections>
<asp:WebPartConnection ID="DashBoardWPC" ProviderID="DashBoardTabWP" ProviderConnectionPointID="TabWebPart"
ConsumerID="DashBoardPageLogicWP" ConsumerConnectionPointID="TabSystem" />
<asp:WebPartConnection ID="TabsToState" ProviderID="DashBoardTabWP" ProviderConnectionPointID="TabWebPart"
ConsumerID="dashBoardStateProvider" ConsumerConnectionPointID="TabSystem" />
<asp:WebPartConnection ID="StatePageContextToPageLogic" ProviderID="dashBoardStateProvider"
ProviderConnectionPointID="DashBoardPageContextExport" ConsumerID="DashBoardPageLogicWP"
ConsumerConnectionPointID="PageContext" />
</StaticConnections>
</asp:ProxyWebPartManager>
<div class="pg-scroll-fixed lx-clear">
<CFBase:BaseWebPartZone runat="server" ID="WPTopZone">
<ZoneTemplate>
<WebParts:TabWebPart runat="server" Description="DashBoard" ID="DashBoardTabWP" ChromType="None"
IsRMLogRequired="true" />
<DashBoardWebParts:DashBoardStateWebPart runat="server" ID="dashBoardStateProvider"
ChromeType="None" ChromeState="Minimized" />
<DashBoardWebParts:DashBoardPageLogic runat="server" ID="DashBoardPageLogicWP" ChromeType="None" />
</ZoneTemplate>
</CFBase:BaseWebPartZone>
</div>
<UC:PartialViewShim runat="server" ID="LandingPageIndex" Area="MedLit" Controller="Research"
View="ResearchView" />
</asp:Content>
动态渲染 css -
$(function () {
var $head = $("#frame").contents().find("head");
$head.append($("<link/>", { rel: "stylesheet", href: '/Pages/CSS/layoutMedLitHome.css', type: "text/css" }));
$head.append($("<link/>", { rel: "stylesheet", href: '/Pages/CSS/Master0.css', type: "text/css" }));
$head.append($("<link/>", { rel: "stylesheet", href: '/Pages/CSS/compNewLexis0.css', type: "text/css" }));
$head.append($("<link/>", { rel: "stylesheet", href: '/Pages/CSS/Search0.css', type: "text/css" }));
alert('head:' + $head.val());
});